To add/remove additional IP manually
 
1. Run the ip command to display the current ip address configuration of the interface
    # ip addr
 
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:16:3c:8b:17:b7 brd ff:ff:ff:ff:ff:ff
    inet 194.5.95.184/24 brd 194.5.95.255 scope global noprefixroute eth0
    valid_lft forever preferred_lft forever
 
NOTE : The interface name may differ to em1, em2, eth0, eth1 etc
 
2. To add an IP address:
    # ip addr add 194.5.95.180/24 dev eth0
 
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:16:3c:8b:17:b7 brd ff:ff:ff:ff:ff:ff
    inet 194.5.95.184/24 brd 194.5.95.255 scope global noprefixroute eth0
    valid_lft forever preferred_lft forever
    inet 194.5.95.180/24 scope global secondary eth0
    valid_lft forever preferred_lft forever
 
 
3. To delete an existing IP
    # ip addr del 194.5.95.180/24 dev eth0
 
NOTE : Manually added IP addresses are tenacious and the changes will get disappear after a reboot or network service restart.
 
To Add/Remove Additional IP tenaciously
 
1. Go to /etc/sysconfig/network-scripts/
    # cd /etc/sysconfig/network-scripts/
    # ls
 
 
2. Let’s assume that you want to create an additional virtual interfaces to bind a single IP addresses 194.5.95.180 to the NIC. We need to create an additional alias file, while “ifcfg-eth0” holds the same primary IP address. This is how to setup an aliases to bind the 194.5.95.180 IP addresses.
 
For each alias you must assign a number sequentially. For example, we copying existing parameters of interface “ifcfg-eth0” in virtual interfaces called ifcfg-eth0:0
    # cp ifcfg-eth0 ifcfg-eth0:0
    # vi ifcfg-eth0:0
 
Rename the DEVICE name from "eth0" to "eth0:0" and change IPADDR ip from Main IP to additional IP you want to add.
 
    DEVICE=eth0:0
    BOOTPROTO=static
    ONBOOT=yes
    IPADDR=194.5.95.180
    GATEWAY=194.5.95.161
    NETMASK=255.255.255.0
 
Once, you’ve made all changes, save all your changes and restart/start the network service for the changes to reflect.
 
    eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 194.5.95.180 netmask 255.255.255.0 broadcast 194.5.95.255
    ether 00:16:3c:8b:17:b7 txqueuelen 1000 (Ethernet)
 
Esta resposta lhe foi útil? 28 Usuários acharam útil (99 Votos)