How to Configure the Second NIC on Enterprise Linux 7 - by Modifying Configuration File

  • by
After you added the second network interface card (NIC) on Enterprise Linux 7, the server can detect the presence of the NIC, but they are not functional until you configure them successfully, either by your bare hands or by nmtui command.
[root@test ~]# ll /sys/class/net/
total 0
lrwxrwxrwx. 1 root root 0 Jul  4 02:28 eno33554992 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:06.0/net/eno33554992
lrwxrwxrwx. 1 root root 0 Jul  4 02:28 eth0 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:01.0/net/eth0
lrwxrwxrwx. 1 root root 0 Jul  4 02:28 lo -> ../../devices/virtual/net/lo

Please note that, nmtui is a text-based user interface for replacing system-network-config-tui on Enterprise Linux 7. Let's configure the second NIC manually.
  1. Make sure the device name and MAC address of the second NIC
  2. [root@test ~]# ifconfig
    ...
    eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet6 fe80::20c:29ff:fe97:5f8c  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:97:4e:76  txqueuelen 1000  (Ethernet)
    ...

  3. Add a udev persistent rule and rename the device as eth1
  4. [root@test ~]# vi /etc/udev/rules.d/70-persistent-ipoib.rules
    ...
    ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="32", ATTR{address}=="00:0c:29:97:4e:76", NAME="eth1"

    Or on this file:
    [root@test ~]# vi /etc/udev/rules.d/70-persistent-net.rules
    Both files can result in the same effects.

  5. Copy a configuration file named ifcfg-eth1 from ifcfg-eth0 for the second NIC.
  6. [root@test ~]# cp -p /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1
  7. Modify the content of the configuration file of eth1
  8. [root@test ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
    ...
    #UUID=...
    DEFROUTE=no
    NAME=eth1
    DEVICE=eth1
    ...
    HWADDR=00:0c:29:97:4e:76
    IPADDR=192.168.68.32
    PREFIX=24
    GATEWAY=192.168.68.1
    ...

    Please notice that I commented out the UUID for avoiding accidental conflicts with other NICs and set DEFROUTE=no to indicate that this is NOT the default route.
  9. Bounce the server
  10. [root@test ~]# init 6
  11. Check the ifconfig
  12. [root@test ~]# ifconfig eth1
    eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    ...

  13. Check the routing table
  14. [root@test ~]# route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    default         192.168.0.1     0.0.0.0         UG    100    0        0 eth0
    192.168.15.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
    192.168.68.0    0.0.0.0         255.255.255.0   U     100    0        0 eth1
    ...

    As you can see, the second NIC (eth1) is working now and it's NOT the default route.
  15. Ping the gateway of eth1
  16. [root@test ~]# ping -c 4 192.168.68.1
    PING 192.168.68.1 (192.168.68.1) 56(84) bytes of data.
    64 bytes from 192.168.68.1: icmp_seq=1 ttl=128 time=0.412 ms
    64 bytes from 192.168.68.1: icmp_seq=2 ttl=128 time=0.368 ms
    64 bytes from 192.168.68.1: icmp_seq=3 ttl=128 time=0.360 ms
    64 bytes from 192.168.68.1: icmp_seq=4 ttl=128 time=0.372 ms

    --- 192.168.68.1 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3002ms
    rtt min/avg/max/mdev = 0.360/0.378/0.412/0.020 ms

Last, back to the kernel.
[root@test ~]# ll /sys/class/net/
total 0
lrwxrwxrwx. 1 root root 0 Jul  4 04:20 eth0 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:01.0/net/eth0
lrwxrwxrwx. 1 root root 0 Jul  4 04:20 eth1 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:06.0/net/eth1
lrwxrwxrwx. 1 root root 0 Jul  4 04:20 lo -> ../../devices/virtual/net/lo

Now the second NIC is activated!

Leave a Reply

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