Ubuntu ships with a number of graphical utilities to configure your network devices.
This document is geared toward server administrators and will focus on managing your network on the command line.
Basic network configuration and hostname on a Ubuntu system are stored in several files which must be edited to create a working configuration:
/etc/network/interfacesdescribes the network interfaces
/etc/hostnameconfigures the nameserver credentials
/etc/hostsresolves IP addresses to hostnames
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.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.
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.
iface eth0 inet static
pre-up /sbin/ethtool -s eth0 speed 1000 duplex full
The following section describes the process of configuring your systems IP address and default gateway needed for communicating on a local area network and the Internet.
Temporary IP Address Assignment
To temporarily configure an IP address, you can use the ifconfig command in the following manner. Just modify the IP address and subnet mask to match your network requirements.$sudo ifconfig eth0 10.0.0.100 netmask 255.255.255.0
verify using $ifconfig eth0 command
To configure a default gateway, you can use the route command in the following manner.Modify the default gateway address to match your network requirements.$sudo route add default gw 10.0.0.1 eth0
Verify the gateway configuration using $route -n command.
If you require DNS for your temporary network configuration, you can add DNS server IP addresses in the file /etc/resolv.conf. In general, editing /etc/resolv.conf directly is not recommended, but this is a temporary and non-persistent configuration. The example below shows how to enter two DNS servers to /etc/resolv.conf, which should be changed to servers appropriate for your network.nameserver 22.214.171.124
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
Dynamic IP Address Assignment (DHCP Client)
To configure your server to use DHCP for dynamic address assignment, add the dhcp method to the inet address family statement for the appropriate interface in the file /etc/network/interfaces.
iface eth0 inet dhcp
Static IP Address Assignment
To configure your system to use a static IP address assignment, add the static method to the inet address family statement for the appropriate interface in the file /etc/network/interfaces.
iface eth0 inet static
The loopback interface is identified by the system as lo and has a default IP address of 127.0.0.1. It can be viewed using the ifconfig command.$ifconfig lo
By default, there should be two lines in /etc/network/interfaces responsible for automatically configuring your loopback interface. It is recommended that you keep the default settings unless you have a specific purpose for changing them. An example of the two default lines are shown below.
iface lo inet loopback
Name resolution as it relates to IP networking is the process of mapping IP addresses to hostnames, making it easier to identify resources on a network.
Traditionally, the file /etc/resolv.conf was a static configuration file that rarely needed to be changed or automatically changed via DCHP client hooks. Nowadays, a computer can switch from one network to another quite often and the resolvconf framework is now being used to track these changes and update the resolver's configuration automatically. It acts as an intermediary between programs that supply nameserver information and applications that need nameserver information.
To configure the resolver, add the IP addresses of the nameservers that are appropriate for your network in the file /etc/network/interfaces. You can also add an optional DNS suffix search-lists to match your network domain names.
iface eth0 inet staticaddress 192.168.3.3
dns-nameservers 192.168.3.45 192.168.8.10
Static hostnames are locally defined hostname-to-IP mappings located in the file /etc/hosts. Entries in the hosts file will have precedence over DNS by default. This means that if your system tries to resolve a hostname and it matches an entry in /etc/hosts, it will not attempt to look up the record in DNS. In some configurations, especially when Internet access is not required, servers that communicate with a limited number of resources can be conveniently set to use static hostnames instead of DNS.
The following is an example of a hosts file where a number of local servers have been identified by simple hostnames, aliases and their equivalent Fully Qualified Domain Names (FQDN's).127.0.0.1 localhost
10.0.0.11 server1 server1.example.com vpn
10.0.0.12 server2 server2.example.com mail
10.0.0.13 server3 server3.example.com www
10.0.0.14 server4 server4.example.com file
Name Service Switch Configuration
The order in which your system selects a method of resolving hostnames to IP addresses is controlled by the Name Service Switch (NSS) configuration file /etc/nsswitch.conf. As mentioned in the previous section, typically static hostnames defined in the systems /etc/hosts file have precedence over names resolved from DNS. The following is an example of the line responsible for this order of hostname lookups in the file /etc/nsswitch.conf.hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
- files first tries to
resolve static hostnames located in /etc/hosts.
- mdns4_minimal attempts
to resolve the name using Multicast DNS.
- [NOTFOUND=return] means
that any response of notfound by the preceding mdns4_minimal process
should be treated as authoritative and that the system should not
try to continue hunting for an answer.
- dns represents a legacy
unicast DNS query.
- mdns4 represents a
Multicast DNS query.
hosts: files dns [NOTFOUND=return] mdns4_minimal mdns4
Bridging multiple interfaces is a more advanced configuration, but is very useful in multiple scenarios. One scenario is setting up a bridge with multiple network interfaces, then using a firewall to filter traffic between two network segments. Another scenario is using bridge on a system with one interface to allow virtual machines direct access to the outside network. The following example covers the latter scenario.Before configuring a bridge you will need to install the bridge-utils package. To install the package, in a terminal enter:
sudo apt install bridge-utils
Next, configure the bridge by editing /etc/network/interfaces:
iface lo inet loopback
iface br0 inet static
Enter the appropriate values for your physical interface and network.
Now bring up the bridge:
sudo ifup br0
The new bridge interface should now be up and running. The brctl provides useful information about the state of the bridge, controls which interfaces are part of the bridge, etc. See man brctl for more information.