Monday, October 6, 2008

Configuring Network in Linux

1. DHCP Environment:

Using DHCP Client Daemon
# dhcpcd

Eg: # dhcpcd eth0
where interface is eth0, default Ethernet (LAN) Card interface.

2. Static IP Assigning:

# ifconfig netmask
# route add default gw dev
# echo "nameserver " > /etc/resolv.conf

Eg: Static ip = 192.168.0.12; subnet = 255.255.255.0
gateway = 192.168.0.1; primary dns server = 192.168.0.2

# ifconfig eth0 192.168.0.12 netmask 255.255.255.0
# route add default gw 192.168.0.1 dev eth0
# echo "nameserver 192.168.0.2" > /etc/resolv.conf


The first command assigns an IP address to the interface.

The second command adds the route information, so the system can reach other machines. It adds the default gateway for the packets to get routed to a gateway system. This command can be replaced by a more specific command
# route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth0
This adds a route to all packets to network 192.168.0.0 to go through interface eth0 to gateway 192.168.0.1 for gettting routed to their destination.

The third command adds the DNS server IP to resolv.conf. Whenever a request comes for any DNS name resolution, resolv.conf is checked for the DNS servers to query the information.

3. Verification:

# ifconfig | grep inet
# ping -c 2 www.google.com

The first command gives the IP address assigned.

The second command can be used to verify the route and dns working.
If there is positive response from the ping, then the network settings are complete.
Else try to ping to another system in the same network. If this is positive, then there might be a problem reaching DNS server and need to be checked. If this is negative, then routing information needs to be checked. "route -v" gives the routing information required.

No comments: