Ubuntu network configuration, super simple (version 18.04 or above)
Ubuntu network configuration, super simple (version 18.04 or above)
The Ubuntu operating system provides users with multiple ways to configure network settings to meet the needs of different environments. This article mainly provides a preliminary introduction to Ubuntu network configuration, including the steps to configure multiple IP addresses for a single network card.
To configure Ubuntu networking, we first need to understand the main network configuration files and related commands.
The main configuration files are located in the /etc/network/interfaces and /etc/netplan/ folders.
The /etc/network/interfaces file is mainly used in server versions of Ubuntu systems.
The files in the /etc/netplan/ folder are used for new versions of Ubuntu desktop and server systems.
For multi-IP configuration, we can follow these steps:
1. Open a terminal and log in with administrator rights.
sudo su
[enter administrator password]
vim /etc/netplan/50-cloud-init.yaml
Why 50?
In Ubuntu and other Linux systems, the number "50" usually indicates that the file is part of the system's network configuration. The number "50" itself has no specific meaning, but is intended to identify and organize the multiple network profiles in the system. The number "50" may be used in different configuration files on different systems and versions, but they are generally used to define network settings and parameters.
2. Find the network card you want to configure in the file. In the configuration file, you can see lines like this:
eth0:
This means that we want to configure the network card named eth0.
3. Add multiple IP addresses under the network card configuration. For example, to add two IP addresses (192.168.1.10/24 and 192.168.1.20/24), you would write:
eth0:
dhcp4: no
addresses: [192.168.1.10/24, 192.168.1.20/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
In the configuration file above, we use a list to add multiple IP addresses. Multiple IP addresses are separated by commas and enclosed in square brackets. And the addresses of the gateway and DNS server are specified.
4. Save and close the file. In the vim editor, press the Esc key and enter: wq to save and exit.
5. Apply the network configuration. Run the following command to make the configuration take effect:
netplan apply
Verify whether the configuration takes effect. You can view the details of a network interface with the following command:
ip addr show eth0
You should now be able to see both configured IP addresses.
It should be noted that before performing network configuration, we first need to have administrator rights and understand the applicable scenarios of each configuration method. In some cases, editing network configuration files may require a system restart to take effect.
Attachment: Common commands for configuring the network in Ubuntu
-
ifconfig
: Used to view and change the address and parameters of the network interface. -
netstat
: Used to view information such as network connections, routing tables, interface statistics, etc. -
route
: Used to view and modify the IP routing table. -
ping
: Used to test the network connection and check whether the host is reachable. -
traceroute
: Used to track the path and routing of data packets in the network and to locate network faults.