Ubuntu Network Configuration
Basic network configuration for Ubuntu systems
Section titled “Basic network configuration for Ubuntu systems”0. Specs
Section titled “0. Specs”0.0. Info
Section titled “0.0. Info”Network configuration examples on Ubuntu 22.04 LTS and 24.04 LTS Servers.
Tried to be as thorough as possible: single NIC, multiple NICs, multiple networks.
Debian and Ubuntu network configurations are very different, so there are separate tutorials for Debian and Ubuntu.
0.1. Configuration Files
Section titled “0.1. Configuration Files”Ubuntu 22.04 and 24.04 LTS Servers use Systemd-Networkd and Netplan for network configuration.
Configuration files reside as YAML files in the /etc/netplan directory. A good practice is to have one configuration file there.
This configuration file contains all network configurations, including name servers.
0.2. Sources
Section titled “0.2. Sources”1. Example Configurations
Section titled “1. Example Configurations”1.1. DHCP Configuration
Section titled “1.1. DHCP Configuration”Our NIC is enp0s3.
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: truesudo netplan apply1.2. Static IP Configuration
Section titled “1.2. Static IP Configuration”Our NIC is enp0s3.
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 192.168.1.221/24 nameservers: search: - "x386.org" addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 192.168.1.1sudo netplan apply1.3. Static IP Configuration with 2 IPs
Section titled “1.3. Static IP Configuration with 2 IPs”Our NIC is enp0s3.
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 192.168.1.221/24 - 10.1.1.1/8 nameservers: search: - "x386.org" addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 192.168.1.1sudo netplan apply1.4. Static IP Configuration with 2 NICs
Section titled “1.4. Static IP Configuration with 2 NICs”Our NICs are enp0s3 and enp0s8.
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 192.168.1.221/24 nameservers: search: - "x386.org" addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 192.168.1.1 enp0s8: addresses: - 10.1.1.1/8sudo netplan apply2. Case Study - Multiple Networks
Section titled “2. Case Study - Multiple Networks”2.0. Specs
Section titled “2.0. Specs”We have 2 separate networks (192.168.1.X and 10.X.X.X). Some hosts from one network need to reach hosts in the other network.
We will install a new host to act as a router between the networks.
The host will have 2 NICs (one in each network), and we’ll enable IP routing on it.
This way, hosts in one network will be able to reach hosts in the other network. This will be possible by defining IP routes on the hosts to use the server with 2 NICs as a router to the other network.
Hosts in the 192.168.1.X network use 192.168.1.1 as the default gateway; hosts in the 10.X.X.X network use 10.1.1.1 as the default gateway.
Our router will have 2 NICs: one with IP 192.168.1.216 and the other with IP 10.1.1.216.
Hosts in the 192.168.1.X network will use 192.168.1.216 to reach the 10.X.X.X network. Hosts in the 10.X.X.X network will use 10.1.1.216 to reach the 192.168.1.X network.
We will configure:
- The router (192.168.1.216 & 10.1.1.216)
- The host in the first network (192.168.1.217)
- The host in the second network (10.1.1.218)
Then we’ll check connectivity between them.
2.1. Configuration of the Router
Section titled “2.1. Configuration of the Router”We have 2 NICs (enp0s3 - 192.168.1.X network, and enp0s8 - 10.X.X.X network).
Configure NICs:
- enp0s3: 192.168.1.216/24
- enp0s8: 10.1.1.216/8
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 192.168.1.216/24 nameservers: search: - "x386.org" addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 192.168.1.1 enp0s8: addresses: - 10.1.1.216/8Restart networking (your SSH connection may break; reconnect if needed):
sudo netplan applyEnable IP forwarding:
sudo nano /etc/sysctl.confAdd the following line to the end:
net.ipv4.ip_forward = 1Activate:
sudo sysctl -p2.2. Configuration of the First Host
Section titled “2.2. Configuration of the First Host”We have 1 NIC (enp0s3 - 192.168.1.X network).
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 192.168.1.217/24 nameservers: search: - "x386.org" addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 192.168.1.1 - to: 10.0.0.0/8 via: 192.168.1.216Restart networking (your SSH connection may break; reconnect if needed):
sudo netplan apply2.3. Configuration of the Second Host
Section titled “2.3. Configuration of the Second Host”We have 1 NIC (enp0s3 - 192.168.1.X network).
sudo nano /etc/netplan/50-cloud-init.yamlFill as below:
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 10.1.1.218/8 nameservers: search: - "x386.org" addresses: - 8.8.8.8 - 8.8.4.4 routes: - to: default via: 10.1.1.1 - to: 192.168.1.0/24 via: 10.1.1.216Restart networking (your SSH connection may break; reconnect if needed):
sudo netplan apply2.4. Notes
Section titled “2.4. Notes”The host in the first network can ping the host in the other network now, and vice versa.
Try on the first host (192.168.1.217)
ping 10.1.1.218Try on the second host (10.1.1.218)
ping 192.168.1.217For a host to connect to another host on the other network, routing must be defined on both hosts.
3. NIC Bonding
Section titled “3. NIC Bonding”I tried NIC bonding on Ubuntu, but unfortunately I wasn’t successful.
This might be because of VirtualBox, Netplan, or Networkd. So I gave up. Maybe next time.
I was able to create the bond interface, and it got an IP address too, but it could not connect to anywhere on the network. Even working with Networkd directly didn’t help.