Ubuntu networking

From Ever changing code
Jump to navigation Jump to search

IP configuration

Temporary set IP address

sudo ifconfig eth0 192.168.100.2/24 up
sudo ifconfig eth0 192.168.100.2 netmask 255.255.255.0

Temporary add default GW

sudo route add default gw 192.168.100.1 eth0

Verify your default gateway configuration

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG    0      0        0 eth0
192.168.100.0   0.0.0.0         255.255.255.0   U     1      0        0 eth0

DNS for your temporary network configuration, you can add DNS server IP addresses in the file /etc/resolv.conf. Please bear in mind these changes will be overwritten.

echo "nameserver 8.8.8.8" >> /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

If you no longer need this configuration and wish to purge all IP configuration from an interface, you can use the ip command with the flush option as shown below:

ip addr flush eth0

Permanent changes to IP address are saved in /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	address 	192.168.100.2 	
	netmask 	255.255.255.0 	
	network 	192.168.100.0	
	broadcast 	192.168.100.255	
	gateway 	192.168.100.1
	dns-nameservers 192.168.100.1 8.8.8.8

Wireless from command line

Manual configuration from the command-line

3 steps for WEP
sudo iwconfig eth[N] essid [SSID]
sudo iwconfig eth[N] key restricted s:[PASSWORD]
sudo dhclient
WPA is more complicated
sudo mkdir /etc/wpa_supplicant
cd /etc/wpa_supplicant
sudo echo network = { > wpa_supplicant.conf
sudo echo ssid="SSID" >> wpa_supplicant.conf
sudo echo key_mgmt=WPA-PSK >> wpa_supplicant.conf
sudo echo psk="PRESHAREDKEY" >> wpa_supplicant.conf
sudo echo } >> wpa_supplicant.conf
wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf   #associate the client with the ssid described in 'wpa_supplicant.conf' file
                                                                             # -D driver, -i interface, -c configuration file
                                                                             #use driver wext Linux wireless extensions (generic) for Dell 620/630, 
sudo vi /etc/network/interfaces    #add the network permanently

Now add after "auto eth[N] ..." & "iface eth[N] .." :

wpa-driver wext             #driver for network card, this can be obtained by command 'wpa_supplicant --help | grep -A 5 drivers:'
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Save the file and restart networking sudo service networking restart

Networking Tools

nm-tool - utility to report NetworkManager state and devices, it provides information about NM, device and wireless networks.

Ethernet Interfaces wip... add D620 output ...

Identify Ethernet Interfaces

lshw shows here an interface with the logical name of eth0 along with bus information, driver details and all supported capabilities

sudo lshw -class network
 *-network
      description: Ethernet interface
      product: BCM4401-B0 100Base-TX
      vendor: Broadcom Corporation
      physical id: 0
      bus info: pci@0000:03:00.0
      logical name: eth0
      version: 02
      serial: 00:15:c5:4a:16:5a
      size: 10MB/s
      capacity: 100MB/s
      width: 32 bits
      clock: 33MHz
      capabilities: (snipped for brevity)
      configuration: (snipped for brevity)
      resources: irq:17 memory:ef9fe000-ef9fffff
Ethernet Interface Logical Names

Interface logical names are configured in the file /etc/udev/rules.d/70-persistent-net.rules. If you would like control which interface receives a particular logical name, find the line matching the interfaces physical MAC address and modify the value of NAME=ethX to the desired logical name. Reboot the system to commit your changes.

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:c5:4a:16:5a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:c5:4a:16:5b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
Ethernet Interface Settings

ethtool is a program that displays and changes Ethernet card settings such as auto-negotiation, port speed, duplex mode, and Wake-on-LAN. It is not installed by default, but is available for installation in the repositories.

sudo apt-get install ethtool

The following is an example of how to view supported features and configured settings of an Ethernet interface.

sudo ethtool eth0
Settings for eth0:
       Supported ports: [ TP ]
       Supported link modes:   10baseT/Half 10baseT/Full 
                               100baseT/Half 100baseT/Full 
                               1000baseT/Half 1000baseT/Full 
       Supports auto-negotiation: Yes
       Advertised link modes:  10baseT/Half 10baseT/Full 
                               100baseT/Half 100baseT/Full 
                               1000baseT/Half 1000baseT/Full 
       Advertised auto-negotiation: Yes
       Speed: 1000Mb/s
       Duplex: Full
       Port: Twisted Pair
       PHYAD: 1
       Transceiver: internal
       Auto-negotiation: on
       Supports Wake-on: g
       Wake-on: d
       Current message level: 0x000000ff (255)
       Link detected: yes

Changes made with the ethtool command are temporary and will be lost after a reboot. If you would like to retain settings, simply add the desired ethtool command to a pre-up statement in the interface configuration file /etc/network/interfaces.

The following is an example of how the interface identified as eth0 could be permanently configured with a port speed of 1000Mb/s running in full duplex mode.

auto eth0
iface eth0 inet static
pre-up /usr/sbin/ethtool -s eth0 speed 1000 duplex full

Change the logical name for an interface

[not confirmed that working on Ubunu or Red Hat]

say you have two nics installed on the system, eth0, and eth1. At some times latter, you removed eth0 from the system. Now eth1 is the only nic in your machine... and you want to rename this nic(eth1) as eth0.

rcnetwork stop
vi /etc/udev/rules.d/30-net_persistent_names.rules

here you find a line as

SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:02:b3:22:84:f3", IMPORT="/lib/udev/rename_netiface %k eth1"

simply change eth1, as eth0,

SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:02:b3:22:84:f3", IMPORT="/lib/udev/rename_netiface %k eth0"

save and exit

Now execute the following command

/lib/udev/rename_netiface <old> <new>  i.e  /lib/udev/rename_netiface eth1 eth0
rcnetwork start

even we can give any valid name to our nic, say e.g we want to name our eth0 as lan0, then

rcnetwork stop
vi /etc/udev/rules.d/30-net_persistent_names.rules

here you find a line as

SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:02:b3:22:84:f3", IMPORT="/lib/udev/rename_netiface %k eth0"

simply change eth1, as lan0,

SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:02:b3:22:84:f3", IMPORT="/lib/udev/rename_netiface %k lan0"

Now execute the following command

/lib/udev/rename_netiface eth0 lan0

NOTE: say we gave our nic a name as lanX, nicX, or intX(i.e non ethX name), and then want to change the name from lan0 to eth0, all the above steps are required, and reboot too.

Links and references