Pages

Monday, September 7, 2009

Configure network from command line in Ubuntu 10

A. Temporary settings for the network can be added and tested with the ifconfig command.  to view network settings:

# ifconfig wlan0
or:

# iwconfig wlan0 

iwconfig is similar to ifconfig but dedicated to wireless networks, and shows more information.

For example, to set an ip address for wireless wlan0 interface:

# ifconfig wlan0 192.168.0.22 netmask 255.255.255.0 up

Note that all the commands need super user rights. Use su to switch to root.

$ sudo su

To configure a default gateway, you can use the route command in the following manner. Modify the default gateway address:
# route add default gw 192.168.0.1 wlan0
To verify your default gateway configuration, you can use the route command:

# route -n
To add DNS servers IP addresses, modify the file/etc/resolv.conf. Add nameservers corresponding to your network. For example:
nameserver 89.32.16.2
nameserver 192.168.0.1

B. Permanent settings can be configured for the appropriate interface in the file /etc/network/interfaces. Example for configuring permanent static ip address, gateway and netmask for wireless interface wlan0:

auto wlan0 
iface wlan0 inet static 
address 192.168.0.22 
netmask 255.255.255.0 
gateway 192.168.0.1
After adding interface configuration in this file, the interface can be brought up and down using the commands ifup and ifdown:

sudo ifup eth0
To manually disable the interface, you can use the ifdown command.
sudo ifdown eth0
Links:

No comments:

Post a Comment