Linux Networking
> IP Address
>Subnet Mask
>Gateway
>DNS
eth0 Link encap:Ethernet HWaddr 00:0C:29:AB:A3:CA
inet addr:192.168.222.131 Bcast:192.168.222.255 Mask:255.255.255.0
> Packet Type is - Link encap:Ethernet > MAC add. or Physical Address - HWaddr 00:0C:29:AB:A3:CA > size > 48 Bit. = (24 Bit Vender add. + 24 Bit IANA )
> This work on Layer 2 of OSI model. > Layer 2 also called a data link layer > devices work on layer 2 > Switch, MAC.
> Switch create a MAC Table that is also called - ARP Table (Address Resulation Protocal Table) to transfer the data directally from source to destination
without brodcasting to all.
>In IP subneting the Network Address and Broadcast Adress is not usable.
192.168.0.0 [Network Address]
192.168.0.1
2
3
4
254
192.168.0.255 [Brodcast Address]
> Network Add of any Subneting is called the name of the that particular Network.
> And Broadcast Address helps to convey the massege to all the ip. If we send any data on the broadcast add, its send that data on all IP.
> IPv4 : 32 Bit Add. > 2^8 > 256 > 0 to 255 = 256 Total IP > But usable only 254. > Also we write-/8 -A, /16 - B, /24 - C Subnet > called CIDR.
> IPv6 : 128 Bit Add.
> Loop back / Localhost/localhost.localdomain IP > 127.0.0.1
> While pinging the loopback add. we check that our system is network capable or not . if its ping that means or NIC is working fine.
> Q. When we configure same ip on the two system its conflict. But the loop back add is same on all system but still its not conflict. Why ?
> Ans : Loop back add never conflict because, its does not have any broadcast add. Loop back add never broadcast its ip, so no one can
knows about its ip and it does not conflict with other system. We know about any ip while broadcasting, when some network broadcast
their ip then only other system can know its ip etc.
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
> Q. On a single NIC how many IP we can configure ?
> Ans - On a single NIC all subnet can be configure.
> To creat a virtual NIC we can run these command
[root@server3 ~]# ifconfig eth0:1 192.168.1.5 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:2 192.168.1.6 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:3 192.168.1.7 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:4 192.168.1.8 netmask 255.255.255.0
[Note : But these all are temprory, when we will start the network service or restart the system all the vir. NIC will disconnect automatically. ]
> How we can make it parmanent ?
> Ans : There is two way to make it permanent
1. Run the command > setup > Network Configuration > Device Configuration > New Device > and creat the new NIC
2. Go to the directory > [root@server3 ~]#cd /etc/sysconfig/network-script/
> cp ifcfg-eth0 eth0:1
> cp ifcfg-eth0 eth0:2
> cp ifcfg-eth0 eth0:3
> cp ifcfg-eth0 eth0:4 [like this we can creat multiple of virtual NIC card]
> Now one by one go into the all new created virtual NIC and make the below changes -
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:AB:A3:CA"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
1. Change the Device name > DEVICE="eth0" > DEVICE="eth0:1"
2. If NIC is configured on static then also change the IPADDR & NETMASK after changing the device name.
[Note : The main thing is to be notice in NIC configuration is it's writing style > All the words in the left side is in Capital later and all the right side words is in small later , so do keep in your mind while making any changes in the NIC configuration file.]
3. After these configuration do not forget to restart the network > [root@server3 ~]# service network restart
*Provide range of IP Address::
-------------------------------------
[root@server3 ~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0-range1
IPADDR_START=192.168.1.1
IPADDR_END=192.168.1.200
CLONENUM_START=10
:wq [Save the file]
[root@server3 ~]# service network restart
Q. CLONENUM_START ?
> CLONENUM_START value specifies starting identifier of alias that will be applied to eth1 interface, in
above example the first 192.168.1.1 will be assigned to eth1:10 alias. The last IP of the range 192.168.1.200
will be applied to eth:210 sub-interface. This is totally easy approach.
* Ifconfig :
------------
This command is number one command in the alphabet of Linux networking. It configures
network interfaces. It features include
• Turning certain network interface on and off.
• Changing interface IP address.
• Changing netmask, MTU and other network parameters of the interface.
• Putting interface into promiscuous mode.
* Promiscuous mode ?
-----------------------------
1) In a network, promiscuous mode allows a network device to intercept and read each
network packet that arrives in its entirety. This mode of operation is sometimes given to a
network snoop server that captures and saves all packets for analysis (for example, for
monitoring network usage).
----------------------------------------------------------------------------------------------------------------------
Q. How to configure Static Ethernet network connection in Linux ?
> go to the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and change the
configurations - IP, Netmask, DNS, GATEWAY,
[root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
> After installing CentOS we want to configure IP address. CentOS is mostly used as Server.
So we want to give it a static IP address. By default CentOS interface is configured to receive IP from DHCP server. Here We will see how to configure static IP address in CentOS system.
> Configure Static IP Address in CentOS
The following steps will show the configurations of static IP address in CentOS machine.
1.Files needed for network configuration are under /etc/sysconfig/network-scripts. So open the file with VIM, VI, or nano etc,
2.We will see default configuration like this,
DEVICE=eth0
HWADDR=00:27:0e:0c:70:9b
TYPE=Ethernet
UUID=25a7bad9-616a-48a0-ace5-52aa0af9fdb7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp
3.Now change the configuration to this,
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:0e:0c:70:9b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS2=4.2.2.2
DNS1=8.8.8.8
TYPE=Ethernet
USERCTL=no
[root@server1 ~]#
4. Then save the file, with :wq
5. Now restart the network services by issuing the command,
[root@server1 ~]#service network restart
6. To verify the IP address issue the following command
[root@server1 ~]# ifconfig
You will then see following information,
eth0 Link encap:Ethernet HWaddr 00:27:0E:0C:70:9B
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::227:eff:fe0c:709b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3568 errors:0 dropped:0 overruns:0 frame:0
TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1167465 (1.1 MiB) TX bytes:746010 (728.5 KiB)
Interrupt:50 Base address:0xe000
7. After configuring IP address now let’s configure DNS. Name server or DNS information
is stored in different file. The location is, "/etc/recolv.conf. "using editor to configure DNS
information,
[root@server1 ~]# vim /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.1.10
nameserver 8.8.8.8
:wq (save the file )
The name server IP address can be different depending on your network scenario.
Now save the file and exit. We can test the configuration by issuing ping command.
[root@server1 ~]# ping www.google.com
PING www.google.com (216.58.220.4) 56(84) bytes of data.
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=1 ttl=55 time=31.0 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=2 ttl=55 time=30.9 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=3 ttl=55 time=32.0 ms
If you get the reply, you have successfully configured the IP address and DNS information.
8. After configuring DNS Name Server now we will configure "GATEWAY" from file location "/etc/sysconfig/network".
[root@server1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
GATEWAY=192.168.1.1
HOSTNAME=server1.deo.com
[root@server1 ~]#
:wq (save the file before exit)
9. After configuring GATEWAY we will configure the host name from file location "/etc/hosts"
[root@server1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.10 server1.deo.com server1
:wq (save the file )
> After all the configuration once again restart the network
[root@server1 ~]# service network restart
----------------------------------------------------------------------------------------------------------------------
eth0-Configuration on Linux
Q. How to configure Static Ethernet network connection in Linux ?
* go to the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and change the
configurations - IP, Netmask, DNS, GATEWAY,
[root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
*After installing CentOS we want to configure IP address. CentOS is mostly used as Server.
So we want to give it a static IP address. By default CentOS interface is configured to
receive IP from DHCP server. Here We will see how to configure static IP address in
CentOS system.
* Configure Static IP Address in CentOS
The following steps will show the configurations of static IP address in CentOS machine.
1.Files needed for network configuration are under /etc/sysconfig/network-scripts. So open the file with VIM, VI, or nano etc,
2.We will see default configuration like this,
DEVICE=eth0
HWADDR=00:27:0e:0c:70:9b
TYPE=Ethernet
UUID=25a7bad9-616a-48a0-ace5-52aa0af9fdb7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp
3.Now change the configuration to this,
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:0e:0c:70:9b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS2=4.2.2.2
DNS1=8.8.8.8
TYPE=Ethernet
USERCTL=no
[root@server1 ~]#
4. Then save the file, with :wq
5. Now restart the network services by issuing the command,
[root@server1 ~]#service network restart
6. To verify the IP address issue the following command
[root@server1 ~]# ifconfig
You will then see following information,
eth0 Link encap:Ethernet HWaddr 00:27:0E:0C:70:9B
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::227:eff:fe0c:709b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3568 errors:0 dropped:0 overruns:0 frame:0
TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1167465 (1.1 MiB) TX bytes:746010 (728.5 KiB)
Interrupt:50 Base address:0xe000
7. After configuring IP address now let’s configure DNS. Name server or DNS information
is stored in different file. The location is, "/etc/recolv.conf. "using editor to configure DNS
information,
[root@server1 ~]# vim /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.1.10
nameserver 8.8.8.8
:wq (save the file )
The name server IP address can be different depending on your network scenario.
Now save the file and exit. We can test the configuration by issuing ping command.
[root@server1 ~]# ping www.google.com
PING www.google.com (216.58.220.4) 56(84) bytes of data.
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=1 ttl=55 time=31.0 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=2 ttl=55 time=30.9 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=3 ttl=55 time=32.0 ms
If you get the reply, you have successfully configured the IP address and DNS information.
8. After configuring DNS Name Server now we will configure "GATEWAY" from file location "/etc/sysconfig/network".
[root@server1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
GATEWAY=192.168.1.1
HOSTNAME=server1.deo.com
[root@server1 ~]#
:wq (save the file before exit)
9. After configuring GATEWAY we will configure the host name from file location "/etc/hosts"
[root@server1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.10 server1.deo.com server1
:wq (save the file )
* After all the configuration once again restart the network
[root@server1 ~]# service network restart
----------------------------------------------------------------------------------------------------------------------
CentOS Linux: Add Static Routing
> We can use any one of the following command line utility to add, delete, display, or manipulate the Linux kernel routing table on CentOS and friends:
1.ip command - A CentOS Linux command line tool to print / manipulate routing, devices, policy routing and tunnels.
2.route command - Older command line utility to show or manipulate the Linux kernel routing table. I suggest that you use ip command instead of route command. This command exists for historical and compatibility reasons only.
We need to edit the following configuration files for static route configuration :
1./etc/sysconfig/network - Edit this file to set default gateway IP address.
2./etc/sysconfig/network-scripts/route-ethX - Edit this file to set additional static gateway IP address.
> CentOS: Displaying current routing table
Type any one of the following command:
# netstat -nr
# route -n
# ip route list
#ip route show
[Warning: It is important that you configure routing correctly over ssh based session; otherwise, you will be locked out due to wrong network configuration.]
> CentOS Linux add a default gateway.
In this example, route all traffic via 192.168.1.254 gateway connected via eth0 network interface. The following command will set a default gateway for both internal and external network (if any):
# route add default gw 192.168.1.254 eth0
OR
# ip route add 192.168.1.0/24 dev eth0
Q. How do I make routing changes persistent across CentOS Linux server reboots?
> To set default gateway edit /etc/sysconfig/network as follows:
# cat /etc/sysconfig/network
Sample configuration file:
NETWORKING=yes
## server name ##
HOSTNAME=server1.cyberciti.biz
## Default route ##
GATEWAY=192.168.1.254
NETWORKING_IPV6=yes
IPV6_AUTOCONF=no
>Save and close the file. Restart the networking service on CentOS Linux, type:
# service network restart
# ip route list
>We can add additional static route for eth0 by editing "/etc/sysconfig/network-scripts/route-eth0" file as follows:
10.0.0.0/8 via 10.10.29.65
>The above config sets static routing for network 10.0.0.0/8 via 10.9.38.65 router.
> Debian / Ubuntu Linux persistence static routing configuration
Edit /etc/network/interfaces file, enter:
# vi /etc/network/interfaces
Append the following in eth0 section:
#up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
#down route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
> Save and close the file.
* Generic method to add persistent static routing on Linux
The following method works with almost all Linux distributions.
Edit /etc/rc.d/rc.local or /etc/rc.local, enter
# vi /etc/rc.local
Append the following line:
/sbin/ip route add 192.168.1.0/24 dev eth0
>Save and close the file.
-------------------------------------------------------------------------------------------------------
> IP Address
>Subnet Mask
>Gateway
>DNS
eth0 Link encap:Ethernet HWaddr 00:0C:29:AB:A3:CA
inet addr:192.168.222.131 Bcast:192.168.222.255 Mask:255.255.255.0
> Packet Type is - Link encap:Ethernet > MAC add. or Physical Address - HWaddr 00:0C:29:AB:A3:CA > size > 48 Bit. = (24 Bit Vender add. + 24 Bit IANA )
> This work on Layer 2 of OSI model. > Layer 2 also called a data link layer > devices work on layer 2 > Switch, MAC.
> Switch create a MAC Table that is also called - ARP Table (Address Resulation Protocal Table) to transfer the data directally from source to destination
without brodcasting to all.
>In IP subneting the Network Address and Broadcast Adress is not usable.
192.168.0.0 [Network Address]
192.168.0.1
2
3
4
254
192.168.0.255 [Brodcast Address]
> Network Add of any Subneting is called the name of the that particular Network.
> And Broadcast Address helps to convey the massege to all the ip. If we send any data on the broadcast add, its send that data on all IP.
> IPv4 : 32 Bit Add. > 2^8 > 256 > 0 to 255 = 256 Total IP > But usable only 254. > Also we write-/8 -A, /16 - B, /24 - C Subnet > called CIDR.
> IPv6 : 128 Bit Add.
> Loop back / Localhost/localhost.localdomain IP > 127.0.0.1
> While pinging the loopback add. we check that our system is network capable or not . if its ping that means or NIC is working fine.
> Q. When we configure same ip on the two system its conflict. But the loop back add is same on all system but still its not conflict. Why ?
> Ans : Loop back add never conflict because, its does not have any broadcast add. Loop back add never broadcast its ip, so no one can
knows about its ip and it does not conflict with other system. We know about any ip while broadcasting, when some network broadcast
their ip then only other system can know its ip etc.
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
> Q. On a single NIC how many IP we can configure ?
> Ans - On a single NIC all subnet can be configure.
> To creat a virtual NIC we can run these command
[root@server3 ~]# ifconfig eth0:1 192.168.1.5 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:2 192.168.1.6 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:3 192.168.1.7 netmask 255.255.255.0
[root@server3 ~]# ifconfig eth0:4 192.168.1.8 netmask 255.255.255.0
[Note : But these all are temprory, when we will start the network service or restart the system all the vir. NIC will disconnect automatically. ]
> How we can make it parmanent ?
> Ans : There is two way to make it permanent
1. Run the command > setup > Network Configuration > Device Configuration > New Device > and creat the new NIC
2. Go to the directory > [root@server3 ~]#cd /etc/sysconfig/network-script/
> cp ifcfg-eth0 eth0:1
> cp ifcfg-eth0 eth0:2
> cp ifcfg-eth0 eth0:3
> cp ifcfg-eth0 eth0:4 [like this we can creat multiple of virtual NIC card]
> Now one by one go into the all new created virtual NIC and make the below changes -
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:AB:A3:CA"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
1. Change the Device name > DEVICE="eth0" > DEVICE="eth0:1"
2. If NIC is configured on static then also change the IPADDR & NETMASK after changing the device name.
[Note : The main thing is to be notice in NIC configuration is it's writing style > All the words in the left side is in Capital later and all the right side words is in small later , so do keep in your mind while making any changes in the NIC configuration file.]
3. After these configuration do not forget to restart the network > [root@server3 ~]# service network restart
*Provide range of IP Address::
-------------------------------------
[root@server3 ~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0-range1
IPADDR_START=192.168.1.1
IPADDR_END=192.168.1.200
CLONENUM_START=10
:wq [Save the file]
[root@server3 ~]# service network restart
Q. CLONENUM_START ?
> CLONENUM_START value specifies starting identifier of alias that will be applied to eth1 interface, in
above example the first 192.168.1.1 will be assigned to eth1:10 alias. The last IP of the range 192.168.1.200
will be applied to eth:210 sub-interface. This is totally easy approach.
* Ifconfig :
------------
This command is number one command in the alphabet of Linux networking. It configures
network interfaces. It features include
• Turning certain network interface on and off.
• Changing interface IP address.
• Changing netmask, MTU and other network parameters of the interface.
• Putting interface into promiscuous mode.
* Promiscuous mode ?
-----------------------------
1) In a network, promiscuous mode allows a network device to intercept and read each
network packet that arrives in its entirety. This mode of operation is sometimes given to a
network snoop server that captures and saves all packets for analysis (for example, for
monitoring network usage).
----------------------------------------------------------------------------------------------------------------------
Q. How to configure Static Ethernet network connection in Linux ?
> go to the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and change the
configurations - IP, Netmask, DNS, GATEWAY,
[root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
> After installing CentOS we want to configure IP address. CentOS is mostly used as Server.
So we want to give it a static IP address. By default CentOS interface is configured to receive IP from DHCP server. Here We will see how to configure static IP address in CentOS system.
> Configure Static IP Address in CentOS
The following steps will show the configurations of static IP address in CentOS machine.
1.Files needed for network configuration are under /etc/sysconfig/network-scripts. So open the file with VIM, VI, or nano etc,
2.We will see default configuration like this,
DEVICE=eth0
HWADDR=00:27:0e:0c:70:9b
TYPE=Ethernet
UUID=25a7bad9-616a-48a0-ace5-52aa0af9fdb7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp
3.Now change the configuration to this,
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:0e:0c:70:9b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS2=4.2.2.2
DNS1=8.8.8.8
TYPE=Ethernet
USERCTL=no
[root@server1 ~]#
4. Then save the file, with :wq
5. Now restart the network services by issuing the command,
[root@server1 ~]#service network restart
6. To verify the IP address issue the following command
[root@server1 ~]# ifconfig
You will then see following information,
eth0 Link encap:Ethernet HWaddr 00:27:0E:0C:70:9B
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::227:eff:fe0c:709b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3568 errors:0 dropped:0 overruns:0 frame:0
TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1167465 (1.1 MiB) TX bytes:746010 (728.5 KiB)
Interrupt:50 Base address:0xe000
7. After configuring IP address now let’s configure DNS. Name server or DNS information
is stored in different file. The location is, "/etc/recolv.conf. "using editor to configure DNS
information,
[root@server1 ~]# vim /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.1.10
nameserver 8.8.8.8
:wq (save the file )
The name server IP address can be different depending on your network scenario.
Now save the file and exit. We can test the configuration by issuing ping command.
[root@server1 ~]# ping www.google.com
PING www.google.com (216.58.220.4) 56(84) bytes of data.
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=1 ttl=55 time=31.0 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=2 ttl=55 time=30.9 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=3 ttl=55 time=32.0 ms
If you get the reply, you have successfully configured the IP address and DNS information.
8. After configuring DNS Name Server now we will configure "GATEWAY" from file location "/etc/sysconfig/network".
[root@server1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
GATEWAY=192.168.1.1
HOSTNAME=server1.deo.com
[root@server1 ~]#
:wq (save the file before exit)
9. After configuring GATEWAY we will configure the host name from file location "/etc/hosts"
[root@server1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.10 server1.deo.com server1
:wq (save the file )
> After all the configuration once again restart the network
[root@server1 ~]# service network restart
----------------------------------------------------------------------------------------------------------------------
eth0-Configuration on Linux
Q. How to configure Static Ethernet network connection in Linux ?
* go to the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and change the
configurations - IP, Netmask, DNS, GATEWAY,
[root@server1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
*After installing CentOS we want to configure IP address. CentOS is mostly used as Server.
So we want to give it a static IP address. By default CentOS interface is configured to
receive IP from DHCP server. Here We will see how to configure static IP address in
CentOS system.
* Configure Static IP Address in CentOS
The following steps will show the configurations of static IP address in CentOS machine.
1.Files needed for network configuration are under /etc/sysconfig/network-scripts. So open the file with VIM, VI, or nano etc,
2.We will see default configuration like this,
DEVICE=eth0
HWADDR=00:27:0e:0c:70:9b
TYPE=Ethernet
UUID=25a7bad9-616a-48a0-ace5-52aa0af9fdb7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp
3.Now change the configuration to this,
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:27:0e:0c:70:9b
IPADDR=192.168.1.10
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
DNS2=4.2.2.2
DNS1=8.8.8.8
TYPE=Ethernet
USERCTL=no
[root@server1 ~]#
4. Then save the file, with :wq
5. Now restart the network services by issuing the command,
[root@server1 ~]#service network restart
6. To verify the IP address issue the following command
[root@server1 ~]# ifconfig
You will then see following information,
eth0 Link encap:Ethernet HWaddr 00:27:0E:0C:70:9B
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::227:eff:fe0c:709b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3568 errors:0 dropped:0 overruns:0 frame:0
TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1167465 (1.1 MiB) TX bytes:746010 (728.5 KiB)
Interrupt:50 Base address:0xe000
7. After configuring IP address now let’s configure DNS. Name server or DNS information
is stored in different file. The location is, "/etc/recolv.conf. "using editor to configure DNS
information,
[root@server1 ~]# vim /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.1.10
nameserver 8.8.8.8
:wq (save the file )
The name server IP address can be different depending on your network scenario.
Now save the file and exit. We can test the configuration by issuing ping command.
[root@server1 ~]# ping www.google.com
PING www.google.com (216.58.220.4) 56(84) bytes of data.
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=1 ttl=55 time=31.0 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=2 ttl=55 time=30.9 ms
64 bytes from bom05s05-in-f4.1e100.net (216.58.220.4): icmp_seq=3 ttl=55 time=32.0 ms
If you get the reply, you have successfully configured the IP address and DNS information.
8. After configuring DNS Name Server now we will configure "GATEWAY" from file location "/etc/sysconfig/network".
[root@server1 ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
GATEWAY=192.168.1.1
HOSTNAME=server1.deo.com
[root@server1 ~]#
:wq (save the file before exit)
9. After configuring GATEWAY we will configure the host name from file location "/etc/hosts"
[root@server1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.10 server1.deo.com server1
:wq (save the file )
* After all the configuration once again restart the network
[root@server1 ~]# service network restart
----------------------------------------------------------------------------------------------------------------------
CentOS Linux: Add Static Routing
> We can use any one of the following command line utility to add, delete, display, or manipulate the Linux kernel routing table on CentOS and friends:
1.ip command - A CentOS Linux command line tool to print / manipulate routing, devices, policy routing and tunnels.
2.route command - Older command line utility to show or manipulate the Linux kernel routing table. I suggest that you use ip command instead of route command. This command exists for historical and compatibility reasons only.
We need to edit the following configuration files for static route configuration :
1./etc/sysconfig/network - Edit this file to set default gateway IP address.
2./etc/sysconfig/network-scripts/route-ethX - Edit this file to set additional static gateway IP address.
> CentOS: Displaying current routing table
Type any one of the following command:
# netstat -nr
# route -n
# ip route list
#ip route show
[Warning: It is important that you configure routing correctly over ssh based session; otherwise, you will be locked out due to wrong network configuration.]
> CentOS Linux add a default gateway.
In this example, route all traffic via 192.168.1.254 gateway connected via eth0 network interface. The following command will set a default gateway for both internal and external network (if any):
# route add default gw 192.168.1.254 eth0
OR
# ip route add 192.168.1.0/24 dev eth0
Q. How do I make routing changes persistent across CentOS Linux server reboots?
> To set default gateway edit /etc/sysconfig/network as follows:
# cat /etc/sysconfig/network
Sample configuration file:
NETWORKING=yes
## server name ##
HOSTNAME=server1.cyberciti.biz
## Default route ##
GATEWAY=192.168.1.254
NETWORKING_IPV6=yes
IPV6_AUTOCONF=no
>Save and close the file. Restart the networking service on CentOS Linux, type:
# service network restart
# ip route list
>We can add additional static route for eth0 by editing "/etc/sysconfig/network-scripts/route-eth0" file as follows:
10.0.0.0/8 via 10.10.29.65
>The above config sets static routing for network 10.0.0.0/8 via 10.9.38.65 router.
> Debian / Ubuntu Linux persistence static routing configuration
Edit /etc/network/interfaces file, enter:
# vi /etc/network/interfaces
Append the following in eth0 section:
#up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
#down route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
> Save and close the file.
* Generic method to add persistent static routing on Linux
The following method works with almost all Linux distributions.
Edit /etc/rc.d/rc.local or /etc/rc.local, enter
# vi /etc/rc.local
Append the following line:
/sbin/ip route add 192.168.1.0/24 dev eth0
>Save and close the file.
-------------------------------------------------------------------------------------------------------
No comments:
Post a Comment