How to configure a static IP address on Ubuntu?

by buster.gaylord , in category: Networking & Wireless , a year ago

How to configure a static IP address on Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by emilia_hackett , a year ago

@buster.gaylord 

To configure a static IP address on Ubuntu, you can follow these steps:

  1. Open the terminal by pressing Ctrl + Alt + T.
  2. Type the command sudo nano /etc/netplan/00-installer-config.yaml and press Enter. This will open the Netplan configuration file in the Nano text editor.
  3. Edit the configuration file to specify the static IP address you want to use. Here is an example configuration file:
1
2
3
4
5
6
7
8
9
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]


Replace enp0s3 with the name of your network interface, which you can find by running the command ip link.


Replace 192.168.1.100 with the static IP address you want to use.


Replace 192.168.1.1 with the IP address of your gateway.


Replace 8.8.8.8,8.8.4.4 with the IP addresses of your DNS servers.

  1. Save the configuration file by pressing Ctrl + X, then Y, then Enter.
  2. Apply the new configuration by running the command sudo netplan apply.


That's it! Your Ubuntu system should now be configured with a static IP address.

by damian_mills , 5 months ago

@buster.gaylord 

Note: These steps are applicable for Ubuntu versions 17.10 and later, as they use Netplan for network configuration. Earlier versions of Ubuntu use the /etc/network/interfaces file for network configuration.


If you are using an earlier version of Ubuntu, you can follow these steps to configure a static IP address:


Open the terminal by pressing Ctrl + Alt + T. Type the command sudo nano /etc/network/interfaces and press Enter. This will open the network configuration file in the Nano text editor. Locate the line that starts with "iface" and specifies your network interface (e.g., iface eth0 inet dhcp). Change "dhcp" to "static". Add the following lines below the "iface" line to specify the static IP address, gateway, and DNS servers:


1 2 3 4 5


address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 8.8.4.4


Replace 192.168.1.100 with the static IP address you want to use. Replace 192.168.1.1 with the IP address of your gateway. Replace 8.8.8.8 8.8.4.4 with the IP addresses of your DNS servers. Save the configuration file by pressing Ctrl + X, then Y, then Enter. Restart the networking service by running the command sudo service network-manager restart. That's it! Your Ubuntu system should now be configured with a static IP address.