Step-By-Step Ubuntu Server Network Configuration Tutorial

A-digital-illustration-of-a-modern-Linux-server-prominently-featuring
03/16/2024 •

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.

Ubuntu Server
  • you can also use ifconfig command
    ifconfig
  
  • 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
  
  • 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:

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
  

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
  
  • 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.

https://ubuntu.com/server

https://sanchitgurukul.com/basic-networking

https://sanchitgurukul.com/network-security

Disclaimer: This article may contain information that was accurate at the time of writing but could be outdated now. Please verify details with the latest vendor advisories or contact us at admin@sanchitgurukul.com.

Discover more from

Subscribe now to keep reading and get access to the full archive.

Continue reading