Tuesday, March 31, 2020

Networking in Linux

We can configure the network interfaces on a Linux machine by editing text files stored in the /etc/sysconfig/network-scripts directory.

Illustration:


Network address:                        10.145.72.0

Subnet mask    :                           255.255.254.0    i.e. /23
Primary network interface:        eth0      10.145.72.65
Default gateway:                         10.145.72.1
Broadcast address:                     10.145.73.255

Another interface:                      eth1      172.16.75.12

Subnet:                                        255.255.255.0   i.e. /24
Broadcast:                                  172.16.75.255


Ensure you have the DNS server(s) configuration information in place:

tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / > cat /etc/resolv.conf
search us.company.com
nameserver 120.25.237.31
nameserver 120.25.237.52
nameserver 172.125.82.122
nameserver 133.20.170.70
tabletop.us.company.com: / >

Also makes sure you have entered the default gateway information in the file shown here:

tabletop.us.company.com: / >
tabletop.us.company.com: / > cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=tabletop.us.company.com
GATEWAY=10.145.72.1
NISDOMAIN=nis-company
tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / >

Edit the network interface configuration files as shown here:

tabletop.us.company.com: / >
tabletop.us.company.com: / > cd /etc/sysconfig/network-scripts
tabletop.us.company.com: /etc/sysconfig/network-scripts >
tabletop.us.company.com: /etc/sysconfig/network-scripts >
tabletop.us.company.com: /etc/sysconfig/network-scripts >
tabletop.us.company.com: /etc/sysconfig/network-scripts > vi ifcfg-eth0
tabletop.us.company.com: /etc/sysconfig/network-scripts > 
tabletop.us.company.com: /etc/sysconfig/network-scripts > cat ifcfg-eth0
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
NM_CONTROLLED=no
HWADDR=00:1C:68:47:CA:40
IPADDR=10.145.72.65
NETMASK=255.255.254.0
GATEWAY=10.145.72.1
NETWORK=10.145.72.0
BROADCAST=10.145.73.255
tabletop.us.company.com: /etc/sysconfig/network-scripts >
tabletop.us.company.com: /etc/sysconfig/network-scripts > vi ifcfg-eth1
tabletop.us.company.com: /etc/sysconfig/network-scripts > cat ifcfg-eth1
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)
DEVICE=eth1
BOOTPROTO=static
HWADDR=00:1C:68:47:CA:41
ONBOOT=yes
HOTPLUG=no
IPADDR=172.16.75.12
NETMASK=255.255.255.0
NETWORK=172.16.75.0
TYPE=Ethernet
USERCTL=yes
IPV6INIT=no
PEERDNS=yes
tabletop.us.company.com: /etc/sysconfig/network-scripts >
tabletop.us.company.com: /etc/sysconfig/network-scripts > cd /
tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / >

Restart the network service so the changes take effect:

tabletop.us.company.com: / >
tabletop.us.company.com: / > service network restart
Shutting down interface eth0:
                                                                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                     [  OK  ]
Bringing up loopback interface:                          [  OK  ]
Bringing up interface eth0:                                  [  OK  ]
Bringing up interface eth1:                                  [  OK  ]
tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / > ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:1C:68:47:CA:40
          inet addr:10.145.72.65  Bcast:10.145.73.255  Mask:255.255.254.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1826048 errors:0 dropped:0 overruns:0 frame:0
          TX packets:461001 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:321564798 (306.6 MiB)  TX bytes:151015465 (144.0 MiB)
          Memory:fcae0000-fcb00000

tabletop.us.company.com: / >

tabletop.us.company.com: / > ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:1C:68:47:CA:41
          inet addr:172.16.75.12  Bcast:172.16.75.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:440013 errors:0 dropped:0 overruns:0 frame:0
          TX packets:170774 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:66945052 (63.8 MiB)  TX bytes:9519723 (9.0 MiB)
          Memory:fcac0000-fcae0000

tabletop.us.company.com: / >

tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / >
tabletop.us.company.com: / > route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric       Ref    Use Iface
172.16.75.0     0.0.0.0         255.255.255.0           U       0      0        0 eth1
10.145.0.0      0.0.0.0          255.255.254.0           U       0      0        0 eth0
172.31.0.0      0.0.0.0          255.255.0.0               U       0      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0               U       0      0        0 eth1
0.0.0.0         10.145.72.1       0.0.0.0                   UG      0      0        0 eth0
tabletop.us.company.com: / >
tabletop.us.company.com: / >


Note:  If you make changes to a specific network interface file, say ifcfg-eth0, you can bring the changes into effect, without running the "service network restart" command.   You can run the two following commands:

# ifdown eth0
# ifup eth0




Configuring IPv6 on two servers and getting them to ping each other:

Server 1


pqr923.us.company.com: / >

pqr923.us.company.com: / >
pqr923.us.company.com: / > cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=pqr923.us.company.com
GATEWAY=10.145.120.1
IPV6_AUTOCONF=no
IPV6_DEFAULTGW=2616:d413:418:7f39::1
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / > vi /etc/sysconfig/network-scripts/ifcfg-eth0
pqr923.us.company.com: / > cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=96accc42-9e23-4170-9af1-ea52cfe7cc9e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:37:38:8E:0D:74
IPADDR=10.145.120.175
PREFIX=23
GATEWAY=10.145.120.1
DNS1=175.75.139.82
DNS2=185.50.120.10
DNS3=195.165.32.172
DOMAIN=us.company.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME="System eth0"
IPV6INIT=yes
IPV6ADDR=2616:d413:418:7f39:4000::923
IPV6_DEFAULT=2616:d413:418:7f39::1
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / > service network restart
Shutting down interface eth0:                              [  OK ]
Shutting down loopback interface:                          [  OK ]
Bringing up loopback interface:                            [  OK ]
Bringing up interface eth0:                                [  OK ]
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / > ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:37:38:8E:0D:74
          inet addr:10.145.120.175  Bcast:10.145.121.255 Mask:255.255.254.0
          inet6 addr: 2616:d413:418:7f39:4000::923/64 Scope:Global
          inet6 addr: fe80::221:27ff:fe8e:d34/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:41284 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6229 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2654091 (2.5 MiB)  TX bytes:747366 (729.8 KiB)

pqr923.us.company.com: / > ping6 2616:d413:418:7f39:4000::923

PING 2616:d413:418:7f39:4000::923(2616:d413:418:7f39:4000::923) 56 data bytes
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=3 ttl=64 time=0.027 ms
^C
--- 2616:d413:418:7f39:4000::923 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2446ms
rtt min/avg/max/mdev = 0.027/0.033/0.045/0.008 ms
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / > ping6 2616:d413:418:7f39:4000::924
PING 2616:d413:418:7f39:4000::924(2616:d413:418:7f39:4000::924) 56 data bytes
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=1 ttl=64 time=2.26 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=2 ttl=64 time=0.189 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=3 ttl=64 time=0.184 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=4 ttl=64 time=0.183 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=5 ttl=64 time=0.182 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=6 ttl=64 time=0.181 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=7 ttl=255 time=0.183 ms
^C
--- 2616:d413:418:7f39:4000::924 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6654ms
rtt min/avg/max/mdev = 0.181/0.480/2.262/0.727 ms
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / >
pqr923.us.company.com: / > traceroute6 2616:d413:418:7f39:4000::924
traceroute to 2616:d413:418:7f39:4000::924 (2616:d413:418:7f39:4000::924), 30 hops max, 80 byte packets
 1  2616:d413:418:7f39:4000::924 (2616:d413:418:7f39:4000::924)  0.151 ms !X  0.146 ms !X  0.167 ms !X
pqr923.us.company.com: / >
pqr923.us.company.com: / > route -n -A inet6
Kernel IPv6 routing table
Destination                                 Next Hop                                Flags Metric Ref    Use Iface
2616:d413:418:7f39:4000::924/128            2616:d413:418:7f39:4000::924            UC    0      20       0 eth0
2616:d413:418:7f39::/64                     ::                                      U     256    0        0 eth0
fe80::/64                                   ::                                      U     256    0        0 eth0
::/0                                        2616:d413:418:7f39::1                   UG    1      0        0 eth0
::1/128                                     ::                                      U     0      15       1 lo
2616:d413:418:7f39:4000::923/128            ::                                      U     0      163       1 lo
fe80::221:27ff:fe8e:d34/128                 ::                                      U     0      16       1 lo
ff00::/8                                    ::                                      U     256    0        0 eth0
pqr923.us.company.com: / >
pqr923.us.company.com: / >

Server 2


pqr924.us.company.com: / >

pqr924.us.company.com: / >
pqr924.us.company.com: / > cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=pqr924.us.company.com
GATEWAY=10.145.120.1
IPV6_AUTOCONF=no
IPV6_DEFAULTGW=2616:d413:418:7f39::1
pqr924.us.company.com: / >
pqr924.us.company.com: / > vi /etc/sysconfig/network-scripts/ifcfg-eth0
pqr924.us.company.com: / > cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=96accc42-9e23-4170-9af1-ea52cfe8da9e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:37:28:8F:0D:48
IPADDR=10.145.120.176
PREFIX=23
GATEWAY=10.145.120.1
DNS1=175.75.139.82
DNS2=185.50.120.10
DNS3=195.165.32.172
DOMAIN=us.company.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME="System eth0"
IPV6INIT=yes
IPV6ADDR=2616:d413:418:7f39:4000::924
IPV6_DEFAULT=2616:d413:418:7f39::1
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / > service network restart
Shutting down interface eth0:                              [  OK ]
Shutting down loopback interface:                          [  OK ]
Bringing up loopback interface:                            [  OK ]
Bringing up interface eth0:                                [  OK ]
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / > ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:37:28:8F:0D:48
          inet addr:10.145.120.176  Bcast:10.145.121.255 Mask:255.255.254.0
          inet6 addr: fe80::221:27ff:fe8e:d78/64 Scope:Link
          inet6 addr: 2616:d413:418:7f39:4000::924/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24737 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4151 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1629720 (1.5 MiB)  TX bytes:512379 (500.3 KiB)

pqr924.us.company.com: / >

pqr924.us.company.com: / > ping6 2616:d413:418:7f39:4000::924
PING 2616:d413:418:7f39:4000::924(2616:d413:418:7f39:4000::924) 56 data bytes
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 2616:d413:418:7f39:4000::924: icmp_seq=2 ttl=64 time=0.027 ms
^C
--- 2616:d413:418:7f39:4000::924 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1990ms
rtt min/avg/max/mdev = 0.027/0.036/0.045/0.009 ms
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / > ping6 2616:d413:418:7f39:4000::923
PING 2616:d413:418:7f39:4000::923(2616:d413:418:7f39:4000::923) 56 data bytes
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=1 ttl=64 time=1.99 ms
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=2 ttl=64 time=0.183 ms
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=3 ttl=64 time=0.185 ms
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=4 ttl=64 time=0.179 ms
64 bytes from 2616:d413:418:7f39:4000::923: icmp_seq=5 ttl=64 time=0.187 ms
^C
--- 2616:d413:418:7f39:4000::923 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4749ms
rtt min/avg/max/mdev = 0.179/0.546/1.999/0.726 ms
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / > traceroute6 2616:d413:418:7f39:4000::923
traceroute to 2616:d413:418:7f39:4000::923 (2616:d413:418:7f39:4000::923), 30 hops max, 80 byte packets
 1  2616:d413:418:7f39:4000::923 (2616:d413:418:7f39:4000::923)  0.783 ms !X  0.693 ms !X  0.593 ms !X
pqr924.us.company.com: / >
pqr924.us.company.com: / >
pqr924.us.company.com: / > route -n -A inet6
Kernel IPv6 routing table
Destination                                 Next Hop                                Flags Metric Ref    Use Iface
2616:d413:418:7f39:4000::923/128            2616:d413:418:7f39:4000::923            UC    0      16       0 eth0
2616:d413:418:7f39::/64                     ::                                      U     256    0        0 eth0
fe80::/64                                   ::                                      U     256    0        0 eth0
::/0                                        2616:d413:418:7f39::1                   UG    1      0        0 eth0
::1/128                                     ::                                      U     0      17       1 lo
2616:d413:418:7f39:4000::924/128            ::                                      U     0      191       1 lo
fe80::221:27ff:fe8e:d78/128                 ::                                      U     0      21       1 lo
ff00::/8                                    ::                                      U     256    0        0 eth0
pqr924.us.company.com: / >
pqr924.us.company.com: / >

No comments:

Post a Comment