Archives

Linux Networking

Network Configuration Files

1.      /etc/hosts         –           local name resolve configuration file

IP address       hostname         alias

Reference “man hosts”

[root@server1 Desktop]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.100 server1.example.com   server1

2.      /etc/resolv.conf                       –           DNS server resolver configuration file

Reference “man resolv.conf”

[root@server1 Desktop]# cat /etc/resolv.conf

# Generated by NetworkManager

search example.com

nameserver 192.168.1.100

3.      /etc/sysconfig/network

[root@server1 Desktop]# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=server1.example.com

NISDOMAIN=nisserver

4.      /etc/sysconfig/networking/scripts/ifcfg-eth0

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

or

[root@server1 Desktop]# cat /etc/sysconfig/networking/devices/ifcfg-eth0

DEVICE=eth0

NM_CONTROLLED=yes

ONBOOT=yes

IPADDR=192.168.1.100

BOOTPROTO=none

NETMASK=255.255.255.0

TYPE=Ethernet

GATEWAY=192.168.1.1

DNS1=192.168.1.100

IPV6INIT=no

USERCTL=no

HWADDR=00:0C:29:D5:D2:1F

PREFIX=24

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

NAME=”System eth0″

UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03

Check the hostname, IP address and interface down and up

ifconfig

ifconfig eth0 up                      or         ifup eth0

ifconfig eht0 down     or         ifdown eth0

iwconfig          –           wireless interface display IP address

ip a

arp

dhclient                       –           renew new IP from DHCP server

hostname, domainname, dnsdomainname, nisdomainname, ypdomainname

-a         –           aliase

-d         –           domain name

-f         –           fully qualified domain name (fqdn)

-i          –           IP address

-y         –           NIS domain name

ethtool eth0     –           information

ethtool –i eth0 –           display driver settings

ethtool –p eth0            –           Blink LAN LED

mii-tool eth0

ip link show eth0

ip addr

ping 192.168.1.100     –           test connectivity

host 192.168.1.100     or         host server1.example.com

nslookup 192.168.1.100                      or         nslookup server1.example.com

dig server1.example.com

Assign IP addrss and restart the service

system-config-network

system-config-network-tui

system-config-network-cmd

service network status | start | restart

service NetworkManager status | start | restart

chkconfig network –list | on | off

chkconfig NetworkManager –list  | on | off

Check the port number and routing command

route

traceroute

netstat

-r          –           display the routing rable

-i          –           display interface statistics

-t          –           shows tcp connection

-u         –           shows udp connection

-a         –           display all sockets (tcp,udp or local)

-p         –           display process IDs

-e         –           display extended information

-l          –           listening

-n         –           numerical

Network monitoring command

nmap

tcpdump

Examples

[root@server1 Desktop]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:D5:D2:1F

inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fed5:d21f/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

collisions:0 txqueuelen:1000

RX bytes:7584 (7.4 KiB)  TX bytes:28359 (27.6 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:16436  Metric:1

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

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

collisions:0 txqueuelen:0

RX bytes:45677 (44.6 KiB)  TX bytes:45677 (44.6 KiB)

[root@server1 Desktop]# ip a

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:d5:d2:1f brd ff:ff:ff:ff:ff:ff

inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0

inet6 fe80::20c:29ff:fed5:d21f/64 scope link

valid_lft forever preferred_lft forever

3: pan0: mtu 1500 qdisc noop state DOWN

link/ether 92:90:4e:e1:44:90 brd ff:ff:ff:ff:ff:ff

[root@server1 Desktop]# ip addr

1: lo: mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:d5:d2:1f brd ff:ff:ff:ff:ff:ff

inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0

inet6 fe80::20c:29ff:fed5:d21f/64 scope link

valid_lft forever preferred_lft forever

3: pan0: mtu 1500 qdisc noop state DOWN

link/ether 92:90:4e:e1:44:90 brd ff:ff:ff:ff:ff:ff

[root@server1 Desktop]# hostname

server1.example.com

[root@server1 Desktop]# hostname -d

example.com

[root@server1 Desktop]# hostname -s

server1

[root@server1 Desktop]# hostname -a

server1

[root@server1 Desktop]# hostname -f

server1.example.com

[root@server1 Desktop]# hostname -i

192.168.1.100

[root@server1 Desktop]# hostname -y

(none)

[root@server1 Desktop]# iwconfig

lo        no wireless extensions.

eth0      no wireless extensions.

pan0      no wireless extensions.

[root@server1 Desktop]# ethtool eth0

Settings for eth0:

Supported ports: [ TP ]

Supported link modes:   10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes:  10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Advertised pause frame use: No

Advertised auto-negotiation: Yes

Speed: 1000Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

MDI-X: Unknown

Supports Wake-on: d

Wake-on: d

Current message level: 0x00000007 (7)

Link detected: yes

[root@server1 Desktop]# ethtool -i eth0

driver: e1000

version: 7.3.21-k6-1-NAPI

firmware-version: N/A

bus-info: 0000:02:01.0

ethtool –s eth0 speed 100 autoneg off

ethtool –S eth0

[root@server1 Desktop]# mii-tool eth0

eth0: negotiated 100baseTx-FD, link ok

[root@server1 Desktop]# host 192.168.1.100

100.1.168.192.in-addr.arpa domain name pointer server1.example.com.

[root@server1 Desktop]# host server1.example.com

server1.example.com has address 192.168.1.100

[root@server1 Desktop]# nslookup server1.example.com

Server:             192.168.1.100

Address:          192.168.1.100#53

Name:  server1.example.com

Address: 192.168.1.100

[root@server1 Desktop]# nslookup 192.168.1.100

Server:             192.168.1.100

Address:          192.168.1.100#53

100.1.168.192.in-addr.arpa     name = server1.example.com.

[root@server1 Desktop]# dig server1.example.com

; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6 <<>> server1.example.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- 11399=”” id:=”” noerror=”” opcode:=”” query=”” span=”” status:=””>

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:

;server1.example.com.                             IN            A

;; ANSWER SECTION:

server1.example.com.              86400      IN            A             192.168.1.100

;; AUTHORITY SECTION:

example.com.                          86400      IN            NS           server1.example.com.

;; Query time: 0 msec

;; SERVER: 192.168.1.100#53(192.168.1.100)

;; WHEN: Sun Dec  2 21:56:55 2012

;; MSG SIZE  rcvd: 67

[root@server1 Desktop]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0   U     1      0        0 eth0

default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

[root@server1 Desktop]# netstat -r

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.1.0     *               255.255.255.0   U         0 0          0 eth0

default         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

[root@server1 Desktop]# netstat -tulnp | grep 22

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2184/sshd

tcp        0      0 :::22                       :::*                        LISTEN      2184/sshd

[root@server1 Desktop]# nmap -sTU -p 21 192.168.1.100

Starting Nmap 5.21 ( http://nmap.org ) at 2012-12-02 22:05 IST

Nmap scan report for server1.example.com (192.168.1.100)

Host is up (0.00020s latency).

PORT   STATE  SERVICE

21/tcp open   ftp

21/udp closed ftp

Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

[root@server1 Desktop]# nmap -sTU -p 22 192.168.1.100

Starting Nmap 5.21 ( http://nmap.org ) at 2012-12-02 22:05 IST

Nmap scan report for server1.example.com (192.168.1.100)

Host is up (0.00042s latency).

PORT   STATE  SERVICE

22/tcp open   ssh

22/udp closed ssh

Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

Bonding/teaming on Redhat Linux 6

All the system admin would like to avoid server outage by having redundancy for root filesystem using mirroring,  Multiple FC links to SAN with help of multi-pathing and many more.So here the question is how do you provide redundancy in network level ? Having a multiple network card will not give any redundancy.In redhat Linux you need to configure bonding to accomplish the network level redundancy.Once you have configured the bonding/teaming by using two NIC cards,kernel will automatically detect the failure of any NIC and work smartly according to that without any riot.Bonding can be used for load sharing as well between two physical links.

The below diagram will explain how the bonding is happening .

NIC Bonding unixArena

Operating system used: Redhat Linux 6.3
NIC Details:

[root@mylinz2 network-scripts]# ifconfig -a |grep eth
eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:04
eth3      Link encap:Ethernet  HWaddr 00:0C:29:79:17:F0
[root@mylinz2 network-scripts]#
Goal:
Configure bonding between eth2 and eth4 with name of bond0.

Step 1:

Add the below line in /etc/modprobe.conf to load the bonding module in to kernel.

alias bond0 bonding

In redhat 6.3 , you need to create new file called “bonding.conf” under /etc/modprobe.d/ with below mentioned line.

# cat /etc/modprobe.d/bonding.conf
alias bond0 bonding

Step 2:

Now time to create a bonding interface configuration file in /etc/sysconfig/network-scripts/ directory like the below one.

[root@mylinz2 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@mylinz2 network-scripts]# cat ifcfg-bond0
#This is congiguration file for bond0.Used NIC’s eth2 & eth4
DEVICE=bond0
IPADDR=192.168.10.25
NETMASK=255.255.255.0
USRCTL=no
ONBOOT=yes
BOOTPRO=none
BONDING_OTPS=”mode=0 miimon=100″
[root@mylinz2 network-scripts]#

Step:3

Create a configuration files under “/etc/sysconfig/network-scripts/” for network interfaces if not exists.If exists,have a contents like the below one.

[root@mylinz2 network-scripts]# cat ifcfg-eth2
DEVICE=eth2
HWADDR=00:0C:29:79:17:FA
BOOTPRO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

[root@mylinz2 network-scripts]# cat ifcfg-eth4
DEVICE=eth4
HWADDR=00:0C:29:79:17:04
BOOTPRO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

Note:Do not copy paste the content from above output.MAC and DEVICE name will differ for each system.

Step:4

Now restart the network service to load the configuration.

Note:Do not restart the network service without server maintenance window.

[root@mylinz2 ~]# service network restart
Shutting down interface eth2:  Device state: 3 (disconnected) [  OK  ]Shutting down interface eth4:  Device state: 3 (disconnected) [  OK  ]Shutting down loopback interface:                             [  OK  ]Bringing up loopback interface:                               [  OK  ]Bringing up interface bond0:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/15
[  OK  ]Bringing up interface eth3:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/16
[  OK  ][root@mylinz2 ~]#

Step:5

Verify whether “bond0″ has come up with IP or not .

[root@mylinz2 Desktop]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
inet addr:192.168.10.25  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:17fa/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3843 (3.7 KiB)  TX bytes:4169 (4.0 KiB)

eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2031 (1.9 KiB)  TX bytes:2064 (2.0 KiB)

eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1812 (1.7 KiB)  TX bytes:2105 (2.0 KiB)

In the above output,you can see NIC eth2 and eth4 have flag “SLAVE” and interface “bond0″ has flag MASTER.Another thing you note both, the NIC interface will show same MAC address.

Step:6

Performing the live test to ensure bonding is providing the fault tolerance.

First i am removing the LAN cable from eth4 and let see what happens.

[root@mylinz2 Desktop]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
inet addr:192.168.10.25  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:17fa/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3843 (3.7 KiB)  TX bytes:4169 (4.0 KiB)

eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2031 (1.9 KiB)  TX bytes:2064 (2.0 KiB)

eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1812 (1.7 KiB)  TX bytes:2105 (2.0 KiB)

Still the bond0 interface is UP and RUNNING fine.At the same time,”RUNNING” flag has disappear from eth4.

Now i have connected LAN cable back to eth4 and pulling out from eth2.

[root@mylinz2 Desktop]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
inet addr:192.168.10.25  Bcast:192.168.10.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe79:17fa/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3843 (3.7 KiB)  TX bytes:4169 (4.0 KiB)

eth2      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2031 (1.9 KiB)  TX bytes:2064 (2.0 KiB)

eth4      Link encap:Ethernet  HWaddr 00:0C:29:79:17:FA
UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
RX packets:11 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1812 (1.7 KiB)  TX bytes:2105 (2.0 KiB)

Still “bond0″ interface running with UP & RUNNING flag.So you have successfully configured bonding on Redhat Linux 6.
To see complete bonding info,use below command.

[root@mylinz2 Desktop]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:79:17:fa
Slave queue ID: 0

Slave Interface: eth4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:79:17:04
Slave queue ID: 0
[root@mylinz2 Desktop]#


To verify the current bonding mode,use below command.

[root@mylinz2 Desktop]# cat /sys/class/net/bond0/bonding/mode
balance-rr 0

You can modify the bonding mode by editing “mode” in the ifcfg-bond0  configuration file.

[root@mylinz2 Desktop]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 |grep -i mode
BONDING_OTPS=”mode=0 miimon=100″

table.tableizer-table { border: 1px solid #CCC; font-family: ; font-size: 12px; } .tableizer-table td { padding: 4px; margin: 3px; border: 1px solid #ccc; } .tableizer-table th { background-color: #104E8B; color: #FFF; font-weight: bold; }

Policy Details

Ploicy Name Code Description
balance-rr 0 Round-Robin policy for fault tolerance
active-backup 1 Active-Backup policy for fault tolerance
balance-xor 2 Exclusive-OR policy for fault tolerance
broadcast 3 All transmissions are sent on all slave interfaces.
802.3ad 4 Dynamic link aggregation policy
balance-tlb 5 Transmit Load Balancing policy for fault tolerance
balance-alb 6 Active Load Balancing policy for fault tolerance

To list the currently configured bonds,

[root@mylinz2 Desktop]# cat /sys/class/net/bonding_masters
bond0