Wednesday, March 3, 2010

How to Change Linux IP address



How to Change Linux IP address




Q. How do I change ip address in Linux?

A. There are different ways to change IP address in Linux

(a) Command Line tools
(b) Modify configuration files
(c) Use GUI tools

Task: Display current IP address and setting for network interface called eth0


Use ifconfig command:

# ifconfig eth0

Output:
eth0      Link encap:Ethernet  HWaddr 00:30:48:5A:BF:46
inet addr:10.5.123.2 Bcast:10.5.123.63 Mask:255.255.255.192
inet6 addr: fe80::230:48ff:fe5a:bf46/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:728204 errors:0 dropped:0 overruns:0 frame:0
TX packets:1097451 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:62774749 (59.8 MiB) TX bytes:1584343634 (1.4 GiB)
Interrupt:177

Task: Change IP address 


 


You can change ip address using ifconfig command itself. To set IP address
192.168.1.5, enter command:

# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up

# ifconfig eth0



To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

How to Change Linux IP address



How to Change Linux IP address




Q. How do I change ip address in Linux?

A. There are different ways to change IP address in Linux

(a) Command Line tools
(b) Modify configuration files
(c) Use GUI tools

Task: Display current IP address and setting for network interface called eth0


Use ifconfig command:

# ifconfig eth0

Output:
eth0      Link encap:Ethernet  HWaddr 00:30:48:5A:BF:46
inet addr:10.5.123.2 Bcast:10.5.123.63 Mask:255.255.255.192
inet6 addr: fe80::230:48ff:fe5a:bf46/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:728204 errors:0 dropped:0 overruns:0 frame:0
TX packets:1097451 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:62774749 (59.8 MiB) TX bytes:1584343634 (1.4 GiB)
Interrupt:177

Task: Change IP address 


 


You can change ip address using ifconfig command itself. To set IP address
192.168.1.5, enter command:

# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up

# ifconfig eth0



To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

Linux change IP address

Linux change IP address

Q. How do I change ip address in Linux?

A. There are different ways to change IP address in Linux

(a) Command Line tools
(b) Modify configuration files
(c) Use GUI tools

Task: Display current IP address and setting for network interface called eth0

Use ifconfig command:

# ifconfig eth0

Output:

eth0      Link encap:Ethernet  HWaddr 00:30:48:5A:BF:46
          inet addr:10.5.123.2  Bcast:10.5.123.63  Mask:255.255.255.192
          inet6 addr: fe80::230:48ff:fe5a:bf46/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:728204 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1097451 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:62774749 (59.8 MiB)  TX bytes:1584343634 (1.4 GiB)
          Interrupt:177

Task: Change IP address 

 

You can change ip address using ifconfig command itself. To set IP address
192.168.1.5, enter command:

# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up

# ifconfig eth0



To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

check banned ip address in Linux



check banned ip address in Linux




How do I find or check IP's that are currently banned using iptables command in Linux? How do I verify that IP address 1.2.3.4 is banned or not in Linux?

The correct syntax to block an IP address under Linux using iptables is as follows:
 
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP

Open a command-line terminal (select Applications > Accessories > Terminal), or login to remote server using the ssh and then type the following command block an ip address 1.2.3.4 as follows:

# /sbin/iptables -A INPUT -s 65.55.44.100 -j DROP

To view blocked IP address, enter:

# iptables -L INPUT -v -n

OR

# iptables -L INPUT -v -n | less

Task: Check Banned IP's Linux


Use the grep command as follows to verify that an IP address 1.2.3.4 is blocked or not:

# iptables -L INPUT -v -n | grep "1.2.3.4"

How Do I Delete or Unblock IP Address 1.2.3.4?


Use the following syntax to delete or unblock an IP address under Linux, enter:

# iptables -D INPUT -s 1.2.3.4 -j DROP

Finally, make sure you save the firewall:

# service iptables save

check banned ip address in Linux



check banned ip address in Linux




How do I find or check IP's that are currently banned using iptables command in Linux? How do I verify that IP address 1.2.3.4 is banned or not in Linux?

The correct syntax to block an IP address under Linux using iptables is as follows:
 
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP

Open a command-line terminal (select Applications > Accessories > Terminal), or login to remote server using the ssh and then type the following command block an ip address 1.2.3.4 as follows:

# /sbin/iptables -A INPUT -s 65.55.44.100 -j DROP

To view blocked IP address, enter:

# iptables -L INPUT -v -n

OR

# iptables -L INPUT -v -n | less

Task: Check Banned IP's Linux


Use the grep command as follows to verify that an IP address 1.2.3.4 is blocked or not:

# iptables -L INPUT -v -n | grep "1.2.3.4"

How Do I Delete or Unblock IP Address 1.2.3.4?


Use the following syntax to delete or unblock an IP address under Linux, enter:

# iptables -D INPUT -s 1.2.3.4 -j DROP

Finally, make sure you save the firewall:

# service iptables save

Iptables Find / Check Banned IP Address

Linux: Iptables Find / Check Banned IP Address

How do I find or check IP's that are currently banned using iptables command in Linux? How do I verify that IP address 1.2.3.4 is banned or not in Linux?

The correct syntax to block an IP address under Linux using iptables is as follows:
 
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP
 
Open a command-line terminal (select Applications > Accessories > Terminal), or login to remote server using the ssh and then type the following command block an ip address 1.2.3.4 as follows:

# /sbin/iptables -A INPUT -s 65.55.44.100 -j DROP

To view blocked IP address, enter:

# iptables -L INPUT -v -n

OR

# iptables -L INPUT -v -n | less

Task: Check Banned IP's Linux

Use the grep command as follows to verify that an IP address 1.2.3.4 is blocked or not:

# iptables -L INPUT -v -n | grep "1.2.3.4"

How Do I Delete or Unblock IP Address 1.2.3.4?

Use the following syntax to delete or unblock an IP address under Linux, enter:

# iptables -D INPUT -s 1.2.3.4 -j DROP

Finally, make sure you save the firewall:

# service iptables save

Linux Random Password Generator Command



How do I generate random passwords on the Linux command line using the bash shell?

You can use the following shell function to generate random password. Edit ~/.bashrc file, enter:
$ vi $HOME/.bashrc
Append the following code:
 
genpasswd() {
local l=$1
[ "$l" == "" ] && l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}

Save and close the file. Source ~/.bashrc again, enter:
$ source ~/.bashrc
To generate random password, enter:
$ genpasswd
To generate 8 character long random password, enter:
$ genpasswd 8

Linux Random Password Generator Command



How do I generate random passwords on the Linux command line using the bash shell?

You can use the following shell function to generate random password. Edit ~/.bashrc file, enter:
$ vi $HOME/.bashrc
Append the following code:
 
genpasswd() {
local l=$1
[ "$l" == "" ] && l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}

Save and close the file. Source ~/.bashrc again, enter:
$ source ~/.bashrc
To generate random password, enter:
$ genpasswd
To generate 8 character long random password, enter:
$ genpasswd 8

Linux Random Password Generator Command

How do I generate random passwords on the Linux command line using the bash shell?

You can use the following shell function to generate random password. Edit ~/.bashrc file, enter:
$ vi $HOME/.bashrc
Append the following code:
 
genpasswd() {
 local l=$1
        [ "$l" == "" ] && l=16
       tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
 
Save and close the file. Source ~/.bashrc again, enter:
$ source ~/.bashrc
To generate random password, enter:
$ genpasswd
To generate 8 character long random password, enter:
$ genpasswd 8