Let’s start with the basic.
To check the ip address assign or interface available.
ip address |
Another command to help identify all network interfaces available to your system is lshw
sudo lshw -class network |
ethtool
is a program that displays and changes Ethernet card settings such as auto-negotiation, port speed, duplex mode, and Wake-on-LAN. The following is an example of how to view the supported features and configured settings of an Ethernet interface.
sudo ethtool ens01 |
Sometime in a fresh install you might not have a ip address auto assign to your system.
To assign an ip address temporary to the ethernet interface you can use the following command.
sudo ip addr add 1.2.3.4/24 dev ens01 |
To bring the interface up or down you can use the following commands.
ip link set dev ens01 up ip link set dev ens01 down |
To verify the ip address of a particular interface, ens01 in our example. You can use the following command
ip address show dev ens01 |
To configure a default gateway you can use the following command.
sudo ip route add default via 1.2.3.254 |
To see the ip route that is currently configure in the system.
ip route show |
To temporary add DNS Server IP address you can add nameserver to the /etc/resolv.conf file. Do remember the configuration if you no longer want to use the manually added DNS Server IP.
nameserver 8.8.8.8 nameserver 8.8.4.4 |
You can flush the ip address that you have configure temporarily with the command.
Do note that the nameserver configure in /etc/resolv.conf must be manually remove or it will be removed in the next reboot.
ip address flush ens01 |
Dynamic IP Address assignment (DHCP Client)
In Ubuntu 22.04 you can leverage on netplan to configure your network settings. To configure your system to use DHCP for dynamic address assignment, create a Netplan in the following folder. /etc/netplan/
Create a yaml file. e.g 00_config.yaml. Add the following to the config file. Change the ens01 to your own ethernet interface.
network: |
The configuration can be applied using the netplan command:
sudo netplan apply |
Static IP Address assignment (DHCP Client)
To configure your system to use static address assignment, create a netplan
configuration in the file /etc/netplan/00_config.yaml
. The example below assumes you are configuring your first Ethernet interface identified as ens01
. Change the addresses
, routes
, and nameservers
values to meet the requirements of your network.
|
The configuration can be applied using the netplan command:
sudo netplan apply |
You can also use netplan to validate the configuration by issuing the following command first,
sudo netplan generate |
Bridging multiple interfaces
Bridging 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:
Configure the bridge by editing your netplan
configuration found in /etc/netplan/
, entering the appropriate values for your physical interface and network:
|
The configuration can be applied using the netplan command:
sudo netplan apply |
You can check out the Ubuntu official Documents for more detailed explanation.