While DHCP automatically assigns IP addresses in most networks, certain scenarios like running servers or enabling port forwarding require a static IP configuration. This guide demonstrates how to set a static IP address on Ubuntu 22.04 using the graphical NetworkManager TUI tool.
Note: Ensure your virtual machine uses bridged networking mode for this configuration.
- Check Current Network Settings
First, verify your current IP address. If the ifconfig command is not available, install the network tools package:
sudo apt update && sudo apt install net-tools
Run ifconfig to view your current IP address. Note this address to avoid conflicts when setting a static IP.
- Identify Gateway and Subnet Mask
Use the following command to find your gateway and subnet mask:
route -n
The gateway appears under the "Gateway" column, and the subnet mask under "Genmask." A common subnet mask like 255.255.255.0 corresponds to a /24 prefix.
- Choose DNS Servers
Select DNS servers from the list below:
- 114 DNS: 114.114.114.114, 114.114.115.115
- AliDNS: 223.5.5.5, 223.6.6.6
- Google DNS: 8.8.8.8, 8.8.4.4
- Configure Static IP via NetworkManager TUI
Launch the text-user interface with:
sudo nmtui
Navigate using arrow keys and Enter:
- Select Edit a connection
- Choose your network interface and press Edit
- Change IPv4 configuration from Automatic to Manual
- Fill in:
- IP address (e.g., 192.168.1.100/24)
- Gateway address
- DNS servers (comma-separated)
- Select OK to save
- Exit nmtui and reboot the system
After reboot, your Ubuntu system will use the configured static IP address.