Viewing Network Interfaces
The ip command displays comprehensive details about your network configuration. For example, running:Activating an Interface
To activate an inactive interface (for example, enp0s8), run the following command:- Specifies the link device.
- Uses the
setparameter to configure a property. - Identifies the device using
dev. - Applies the action of bringing the interface UP.
Manually Adding IP Addresses
You can manually assign IP addresses to an interface. For example, to add an IPv4 address to enp0s8:ip -c addr will confirm that the addresses have been added. Remember, an interface can have multiple IP addresses.
Removing IP Addresses and Deactivating an Interface
To remove an IP address (for example, an IPv6 address) and then bring the interface down, use the following commands:Making Permanent Changes with Netplan
Permanent network configurations on Ubuntu Server are managed by Netplan. Netplan reads configuration files from the/etc/netplan directory and instructs lower-level networking services (such as systemd-networkd) to configure the system.
To view the current Netplan configuration, run:
50-cloud-init.yaml. To view its contents, use:
Creating a New Netplan Configuration File
When configuring a different Ethernet device (such as enp0s8) with static IP settings, it’s a good practice to create a new configuration file. Files are processed in alphabetical order, so prefixing your file with a number like99 ensures it is applied last. Here’s an example configuration:
-) indicates a list element; additional properties should be indented correctly.
To apply the new configuration, you have two options. A safe method is to try the configuration first:
--timeout option. If a mistake is made, press Ctrl+C to cancel.
If you see a warning like:Permissions for /etc/netplan/99-mysettings.yaml are too open. Netplan configuration should NOT be accessible by others.Then adjust the file permissions with:
Adding DNS Resolvers and Routes in Netplan
You can further customize your network settings in Netplan by adding DNS resolvers and network routes. Here’s an example configuration to set custom DNS servers for enp0s8 and define routes:nameservers block specifies Google’s public DNS servers. The routes block includes:
- A specific route directing traffic for the 192.168.0.0/24 network via 10.0.0.100.
- A default route directing all other traffic via 10.0.0.1.
/etc/systemd/resolved.conf by uncommenting the DNS line and adding your desired DNS addresses:
Configuring Local Hostname Resolution
For local hostname resolution without relying on external DNS servers, update the/etc/hosts file. For example, to associate the hostname “dbserver” with the IP address 127.0.123.123, add the following line:
Additional Tips and Resources
Netplan YAML files are designed for readability, but they require careful attention to format. If you need further assistance, consult the manual pages:/address or /default routes and then press “n” to navigate through the results.
Example configurations are also provided in /usr/share/doc/netplan/examples. Consider these examples:
-
DHCP Configuration Example:
-
Static Configuration Example: