Linux

How to Add a Second IP Address to Current NIC

Let’s see current setting of all interfaces.
[root@test ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D8:AE:2D
          inet addr:10.0.0.152  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed8:ae2d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:113 errors:0 dropped:0 overruns:0 frame:0
          TX packets:106 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:13135 (12.8 KiB)  TX bytes:15388 (15.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Copy eth0 into eth0:18 and modify it.
[root@test ~]# cp -p /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:18
[root@test ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0:18
DEVICE=eth0:18
TYPE=Ethernet
UUID=aac352a2-6cab-4064-b2bd-2593d3b0cacf
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0C:29:D8:AE:2D
IPADDR=10.0.0.153
PREFIX=24
GATEWAY=10.0.0.129
DNS1=8.8.8.8
DOMAIN=example.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"

Startup the interface
[root@test ~]# ifup ifcfg-eth0:18
Determining if ip address 10.64.43.222 is already in use for device bond0...

Check interfaces again
[root@test ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D8:AE:2D
          inet addr:10.0.0.152  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed8:ae2d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:182 errors:0 dropped:0 overruns:0 frame:0
          TX packets:165 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:19209 (18.7 KiB)  TX bytes:21688 (21.1 KiB)

eth0:18    Link encap:Ethernet  HWaddr 00:0C:29:D8:AE:2D
          inet addr:10.0.0.153  Bcast:10.0.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Leave a Reply

Your email address will not be published. Required fields are marked *