Ubuntu Server Network Configuration
To configure network interfaces and IP addresses on an Ubuntu server, you typically use the netplan tool, which is the default network configuration utility starting from Ubuntu 17.10 (Artful Aardvark) and later versions. Here’s a basic guide on how to do it:
- Find your network interface names: Run the following command to list all network interfaces available on your Ubuntu Server system:
ip addr show
This will show you a list of network interfaces such as eth0, eth1, enp0s3, etc.

- you can also use ifconfig command
ifconfig
root@sanchit:~# ifconfig
ens18: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.23.25.159 netmask 255.255.254.0 broadcast 10.23.25.255
inet6 fe80::be24:11ff:fede:41ac prefixlen 64 scopeid 0x20<link>
ether bc:24:11:de:41:ac txqueuelen 1000 (Ethernet)
RX packets 4259937 bytes 826213829 (826.2 MB)
RX errors 0 dropped 353184 overruns 0 frame 0
TX packets 24848 bytes 2323464 (2.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens23: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 20.5.2.206 netmask 255.255.255.0 broadcast 20.5.2.255
inet6 fe80::be24:11ff:fed2:9451 prefixlen 64 scopeid 0x20<link>
ether bc:24:11:d2:94:51 txqueuelen 1000 (Ethernet)
RX packets 1117352 bytes 73356276 (73.3 MB)
RX errors 0 dropped 214934 overruns 0 frame 0
TX packets 522570 bytes 32143330 (32.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 848 bytes 108345 (108.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 848 bytes 108345 (108.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@sanchit:~#
- Edit Netplan Configuration File: Netplan uses YAML configuration files located in /etc/netplan/. The main configuration file is typically named something like 01-netcfg.yaml or 00-installer-config.yaml under Ubuntu Server.
sudo nano /etc/netplan/01-netcfg.yaml
Or
sudo nano /etc/netplan/00-installer-config.yaml
00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens18: >> You can change the interface type as per your conifguration, i:e eth or ens.
dhcp4: false >> DHCP disbled if you want to enable DHCP replace false with True and save config.
addresses: >> to defien the IP address.
- 10.23.25.159/23
routes: >> you can add multiple routes
- to: 0.0.0.0/0
via: 10.23.24.1
nameservers: >> DNS servers
addresses: [8.8.8.8]
ens23: >> you can add multiple interfaces as per your requirement.
addresses:
- 20.5.2.206/24
version: 2
- Configure the interfaces and IP addresses: Inside the YAML file, you define your network interfaces and their corresponding IP addresses. Here’s a basic example of how it might look in Ubuntu Server:
network:
ethernets:
ens18:
dhcp4: false
addresses:
- 10.23.25.159/23
routes:
- to: 0.0.0.0/0
via: 10.23.24.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
ens23:
addresses:
- 20.5.2.206/24
version: 2
metric: 100
In this example:
- ens18 is the name of the interface.
- dhcp4: false disables DHCP and assigns a static IP address.
- addresses: [10.23.25.159/23] sets the static IP address and subnet mask.
- nameservers: addresses: [8.8.8.8, 8.8.4.4] sets the DNS servers.
- routes section is added to define additional routes.
- – to specifies the destination network in CIDR notation.
- via specifies the gateway for the route.
- metric is an optional parameter to set the priority of the route. Lower values indicate higher priority.
- Adjust the values according to your network configuration.
- Apply the configuration: After you’ve made your changes, save the file and apply the configuration using the following command:
sudo netplan apply
- Verify the configuration: You can verify that the configuration has been applied correctly by checking the network settings in Ubuntu Server:
ip addr
root@sanchit:/etc/netplan# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether bc:24:11:de:41:ac brd ff:ff:ff:ff:ff:ff
altname enp0s18
inet 10.23.25.159/23 brd 10.23.25.255 scope global ens18
valid_lft forever preferred_lft forever
inet6 fe80::be24:11ff:fede:41ac/64 scope link
valid_lft forever preferred_lft forever
3: ens19: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether bc:24:11:01:a2:26 brd ff:ff:ff:ff:ff:ff
altname enp0s19
4: ens20: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether bc:24:11:e3:8d:3b brd ff:ff:ff:ff:ff:ff
altname enp0s20
5: ens21: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether bc:24:11:83:4f:ad brd ff:ff:ff:ff:ff:ff
altname enp0s21
6: ens22: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether bc:24:11:7a:73:01 brd ff:ff:ff:ff:ff:ff
altname enp0s22
7: ens23: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether bc:24:11:d2:94:51 brd ff:ff:ff:ff:ff:ff
altname enp0s23
inet 20.5.2.206/24 brd 20.5.2.255 scope global ens23
valid_lft forever preferred_lft forever
inet6 fe80::be24:11ff:fed2:9451/64 scope link
valid_lft forever preferred_lft forever
These commands will display the current network configuration including IP addresses in Ubuntu Server.
- Use “ip route show” command to check the Routes
ip route show
root@sanchit:/etc/netplan# ip route show
default via 10.23.24.1 dev ens18 proto static
10.23.24.0/23 dev ens18 proto kernel scope link src 10.23.25.159
20.5.2.0/24 dev ens23 proto kernel scope link src 20.5.2.206
- To add temporary Route in Ubuntu Server(it will remove after system or service restart )
sudo ip route add 10.10.0.0/16 via 192.168.1.1 dev ens33
Restart networking service (if necessary): Sometimes, especially on older Ubuntu Server versions, you might need to restart the networking service for changes to take effect. You can do this with:
sudo systemctl restart networking
That’s it! Your Ubuntu Server should now be configured with the specified network interface and IP address.
Useful Links
https://sanchitgurukul.com/basic-networking
https://sanchitgurukul.com/network-security
