Friday, January 23, 2009

Linux Network configuration (Ubuntu)

Linux Network configuration (Ubuntu)

In ubuntu we can easily configure the network using graphical interface. Here we briefly look over the command line configuration.

Determining Your IP Address

When Linux is installed, the ethernet device is called eth0

For wireless interface it will be called wlan0

The ifconfig command.

sahab@sahab:~$ ifconfig

eth0 Link encap:Ethernet HWaddr 00:1d:7d:f8:26:74

inet addr:192.168.2.188 Bcast:192.168.2.255 Mask:255.255.255.0

inet6 addr: fe80::21d:7dff:fef8:2674/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

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

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

collisions:0 txqueuelen:1000

RX bytes:197413652 (188.2 MB) TX bytes:10905457 (10.4 MB)

Interrupt:20 Base address:0x8000

eth0:1 Link encap:Ethernet HWaddr 00:1d:7d:f8:26:74

inet addr:192.168.1.187 Bcast:192.168.1.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Interrupt:20 Base address:0x8000

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:5320 errors:0 dropped:0 overruns:0 frame:0

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

collisions:0 txqueuelen:0

RX bytes:1101301 (1.0 MB) TX bytes:1101301 (1.0 MB)


IP Address changing

#sudo ifconfig eth0 192.168.2.187 netmask 255.255.255.0 up

Configuration file of netwok looks like

# vim /etc/netwok/interfaces

The file looks like

auto lo #For loopback address

iface lo inet loopback

iface eth0 inet static #static ip for eth0

address 192.168.2.188

netmask 255.255.255.0

gateway 192.168.2.254

iface eth0:1 inet static #secondary ip

address 192.168.1.187

netmask 255.255.255.0

auto eth0 #auto enable on boot time

auto eth0:1

Adding secondary ip

#sudo ifconfig eth0:0 192.168.1.187 netmask 255.255.255.0 up


Start and stop - Network

#sudo ifup eth0

#sudo ifdown eth0

#sudo /etc/init.d/networking stop

#sudo /etc/init.d/networking start

#sudo /etc/init.d/networking restart

Default gateway configuration

sahab@sahab:~$sudo route add default gw 192.168.2.254 eth0

Configuring the DNS server

/etc/resolve.conf

Vim /etc/resolve.conf

search example.com

nameserver 192.168.0.2

Checking the current routing table

sahab@sahab:~$ sudo netstat -nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

0.0.0.0 192.168.2.254 0.0.0.0 UG 0 0 0 eth0

Mii-tool and ethtool - Checking network card status and speed

sahab@sahab:~$ sudo mii-tool -v

eth0: negotiated 100baseTx-FD flow-control, link ok

product info: vendor 00:07:32, model 17 rev 2

basic mode: autonegotiation enabled

basic status: autonegotiation complete, link ok

capabilities: 1000baseT-HD 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD

advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control

link partner: 1000baseT-HD 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control


sahab@sahab:~$ sudo 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 auto-negotiation: Yes

Speed: 100Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

Supports Wake-on: pumbg

Wake-on: g

Current message level: 0x00000033 (51)

Link detected: yes


No comments: