Difference between revisions of "Ubuntu networking"

From Ever changing code
Jump to navigation Jump to search
 
Line 47: Line 47:
*<tt>inet dhcp</tt> - Acquire ip through dhcp protocol.
*<tt>inet dhcp</tt> - Acquire ip through dhcp protocol.
*<tt>inet6 static</tt> - Defines a static ipv6 address.
*<tt>inet6 static</tt> - Defines a static ipv6 address.
= Resolvconf =
Switch to resolvconf for /etc/resolv.conf management in Ubuntu 12.04. This is the result of the implementation of: [https://blueprints.launchpad.net/ubuntu/+spec/foundations-p-dns-resolving foundations-p-dns-resolving]
resolvconf is a set of script and hooks managing DNS resolution. The most notable difference for the user is that any change manually done to /etc/resolv.conf will be lost as it gets overwritten next time something triggers resolvconf. Instead, resolvconf uses DHCP client hooks, a Network Manager plugin and /etc/network/interfaces to generate a list of nameservers and domain to put in /etc/resolv.conf.
Resolvconf has a <tt>/etc/resolvconf/resolv.conf.d/</tt> directory that can contain '''base''', '''head''', '''original''' and '''tail''' files. All in <tt>resolv.conf</tt> format.
*'''base''': Used when no other data can be found
*'''head''': Used for the header of resolv.conf, can be used to ensure a DNS server is always the first one in the list
*'''original''': Just a backup of your resolv.conf at the time of resolvconf installation
*'''tail''': Any entry in tail is appended at the end of the resulting resolv.conf. In some cases, upgrading from a previous Ubuntu release, will make tail a symlink to original (when we think you manually modified resolv.conf in the past)
Add nameservers, search path etc outside of your dhcp assignments
$ sudo vi /etc/resolvconf/resolv.conf.d/base #add below:
  nameserver 192.168.1.254
  search home.local
$ sudo resolvconf -u  #update resolv.conf


= Wireless from command line =
= Wireless from command line =

Latest revision as of 22:11, 2 August 2017

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

Networking configuration file - Debian based distros

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
       dns-domain acme.com      #optional
       dns-search acme.com      #adds search entry to /etc/resolv.conf

Options on ethernet interfaces:

  • inet static - Defines a static ip address.
  • inet manual - Does not define an ip address to a interface. Generally used by interfaces that are bridge or aggregation members, or have a vlan device configured on it.
  • inet dhcp - Acquire ip through dhcp protocol.
  • inet6 static - Defines a static ipv6 address.

Resolvconf

Switch to resolvconf for /etc/resolv.conf management in Ubuntu 12.04. This is the result of the implementation of: foundations-p-dns-resolving

resolvconf is a set of script and hooks managing DNS resolution. The most notable difference for the user is that any change manually done to /etc/resolv.conf will be lost as it gets overwritten next time something triggers resolvconf. Instead, resolvconf uses DHCP client hooks, a Network Manager plugin and /etc/network/interfaces to generate a list of nameservers and domain to put in /etc/resolv.conf.

Resolvconf has a /etc/resolvconf/resolv.conf.d/ directory that can contain base, head, original and tail files. All in resolv.conf format.

  • base: Used when no other data can be found
  • head: Used for the header of resolv.conf, can be used to ensure a DNS server is always the first one in the list
  • original: Just a backup of your resolv.conf at the time of resolvconf installation
  • tail: Any entry in tail is appended at the end of the resulting resolv.conf. In some cases, upgrading from a previous Ubuntu release, will make tail a symlink to original (when we think you manually modified resolv.conf in the past)

Add nameservers, search path etc outside of your dhcp assignments

$ sudo vi /etc/resolvconf/resolv.conf.d/base #add below:
  nameserver 192.168.1.254
  search home.local
$ sudo resolvconf -u   #update resolv.conf

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 dhclient wlan0                #to obtain IP address via dhcp
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

Example of /etc/network/interfaces part for a wireless WPA-PSK configuration
auto wlan0                                                  auto wlan0
iface wlan0 inet dhcp                                       iface wlan0 inet static
      wpa-driver wext                                             wpa-driver wext
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf            wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
								              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

Networking Tools

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

Remove Network Manager

Tested on Ubuntu 15.10

sudo service network-manager stop
sudo apt-get remove --purge network-manager network-manager-gnome network-manager-pptp network-manager-pptp-gnome
ps aux | grep etwork        #this shows if NM brought the network up
sudo service networking restart  #at this point you may still have some processes calling NetworkManager DHCPclient configuration running
sudo reboot
Be careful - this may remove udev scripts that generate the interface names dynamically

Error: lost self generated ethX interface name

$ ip addr | grep -A1 ^2    #grep lines starting with '2' including -A1 one line after
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether 00:0c:29:63:6d:19 brd ff:ff:ff:ff:ff:ff

There is missing udev file

/etc/udev/rules.d/70-persistent-net.rules

Solution (not confirmed, not worked

sudo sudo service udev status           #check if the service is healthy 
sudo apt-get install udev udev-discover
sudo udevadm trigger --type=devices --action=change
sudo udevadm control --reload-rules
sudo /lib/udev/write_net_rules  all_interfaces
sudo /lib/udev/rules.d/75-persistent-net-generator-rules

Ethernet Interfaces

Identify Ethernet Interfaces, output from Dell D620

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