VMWARE Linux – Adding a Second NIC for a Guest Linux VM – With No Service Disruption

This is post is to explain the  configuration of  a linux VM with a secondary NIC  without reboot or restart network services. This is fairly simple and straight forward task, but I am just posting it for the folks who are new for the Linux VM on Vmware.

 

Unlike physical systems you don’t need to shutdown the box to add new physical NIC card ( just in case if you don’t have enough on board interface) . Once the VMWARE engineer creates a Virtual NIC on Hypervisor and attach it to our system, linux will automatically recognize the new device and will show you in the ifconfig output.

In the blow example, the scenario is we are actually configuring a secondary interface and attaching a network IP to it, and then we are adding additional static routes for the secondary IP.

Below is the Initial configuration, before detecting the new NIC port:

[root@gurkullinuxVM ~]# ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:50:56:20:26:24

          inet addr:199.9.200.101 Bcast:14.129.48.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:224666676 errors:0 dropped:0 overruns:0 frame:0

          TX packets:161900293 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:5000

          RX bytes:41534486993 (38.6 GiB)  TX bytes:145549058043 (135.5 GiB)

 

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:163605347 errors:0 dropped:0 overruns:0 frame:0

          TX packets:163605347 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:2256211008871 (2.0 TiB)  TX bytes:2256211008871 (2.0 TiB)

 

 Below is the original Static route configuration before adding additional routes

# netstat -rn

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

100.10.103.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1

199.9.200.101     0.0.0.0         255.255.255.0   U         0 0          0 eth0

0.0.0.0         199.9.200.1     0.0.0.0         UG        0 0          0 eth0

 Current eth0 configuration file as below

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=static

IPADDR=199.9.200.101

NETMASK=255.255.255.0

ONBOOT=yes

$

 

And once the VMWare engineer configures the additional nic for the linux box, the nic port will be automatically visible in the system. And you can see eth1 in the  below ifconfig output

 

[root@gurkullinuxVM ~]# ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:ab:56:20:26:24

          inet addr:199.9.200.101Bcast:14.129.48.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:225650315 errors:0 dropped:0 overruns:0 frame:0

          TX packets:162774611 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:5000

          RX bytes:39536609117 (36.8 GiB)  TX bytes:146395475846 (136.3 GiB)

 

eth1      Link encap:Ethernet  HWaddr 00:ab:56:9C:2A:FC

          BROADCAST MULTICAST  MTU:1500  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:1000

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

 

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:163611622 errors:0 dropped:0 overruns:0 frame:0

          TX packets:163611622 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:2256212079066 (2.0 TiB)  TX bytes:2256212079066 (2.0 TiB)

 

 

Then we have create a new ethernet configuration file for the eth1 as below

$ cat ifcfg-eth1

DEVICE=eth1

BOOTPROTO=static

IPADDR=100.10.103.71

NETMASK=255.255.255.0

ONBOOT=yes

TYPE=Ethernet

 Before you bring up the additional NIC just test for link connection using the ethtool as below

[root@gurkullinuxVM network-scripts]# ethtool eth1

Settings for eth1:

        Supported ports: [ TP ]

        Supported link modes:   1000baseT/Full

                               10000baseT/Full

        Supports auto-negotiation: No

        Advertised link modes:  Not reported

        Advertised auto-negotiation: No

        Speed: 10000Mb/s

        Duplex: Full

        Port: Twisted Pair

        PHYAD: 0

        Transceiver: internal

        Auto-negotiation: off

        Supports Wake-on: uag

        Wake-on: d

        Link detected: yes

 

 

 And once we know the interface is available and the “Link Detected = yes”, we can bring up the additional interface using the configuration we entered in “/etc/sysconfig/network-scripts/ifcfg-eth1” , using the below command.

 

# ifup eth1

Setting ringbuffer settings to maximum for eth1

Increasing txqueuelen for eth1 (from 1000 to 5000)

 

then we can check the new configuration from the ifconfig output as below

 

[root@gurkullinuxVM  network-scripts]# ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:ab:56:20:26:24

          inet addr:199.9.200.101 Bcast:14.129.48.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:226458330 errors:0 dropped:0 overruns:0 frame:0

          TX packets:163348262 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:5000

          RX bytes:39708756293 (36.9 GiB)  TX bytes:147033108626 (136.9 GiB)

 

eth1      Link encap:Ethernet  HWaddr 00:ab:56:9C:2A:FC

          inet addr:100.10.103.71  Bcast:100.10.103.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:735 errors:0 dropped:0 overruns:0 frame:0

          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:5000

          RX bytes:49548 (48.3 KiB)  TX bytes:1120 (1.0 KiB)

 

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:163619066 errors:0 dropped:0 overruns:0 frame:0

          TX packets:163619066 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:2256213415106 (2.0 TiB)  TX bytes:2256213415106 (2.0 TiB)

 

Now the second task is additing static routes for the new IP connection ( i.e. eth1). For that purpose  we have to configure the file “/etc/sysconfig/network-scripts/route-eth1” as shown below. And each entry talks about one route.

 

Entry format :  

<Destination Network address >/ <Desitnation Subnetmask >  via   <Gateway>  dev <network interface>

$ cat route-eth1

100.10.101.0/24 via 100.10.103.1 dev eth1

100.10.102.0/24 via 100.10.103.1 dev eth1

100.10.103.0/24 via 100.10.103.1 dev eth1

100.10.104.0/24 via 100.10.103.1 dev eth1

 Once you have the static route information ready in the file “route-eth1”, you just have to make them active using the below command. Please note that in the below command I am just using the eth1 , which doesn’t affect the existing interface.

 

# ./ifup-routes eth1

 

 

 Now you can check the new route configuration with netstat command as given below:

 

$ netstat -rn

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

100.10.101.0     100.10.103.1     255.255.255.0   UG        0 0          0 eth1

100.10.103.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1

100.10.102.0     100.10.103.1     255.255.255.0   UG        0 0          0 eth1

199.9.200.101     0.0.0.0         255.255.255.0   U         0 0          0 eth0

100.10.104.0     100.10.103.1     255.255.255.0   UG        0 0          0 eth1

0.0.0.0         199.9.200.1    0.0.0.0         UG        0 0          0 eth0

$

 

That’s it for the day

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

1 Response

  1. September 17, 2015

    […] Read – Adding a Second NIC for an active Guest Linux VM ( VMWARE) […]

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us