close
close
How To Set Static Ip Ubuntu Server 20 04

How To Set Static Ip Ubuntu Server 20 04

3 min read 23-11-2024
How To Set Static Ip Ubuntu Server 20 04

Setting a static IP address on your Ubuntu 20.04 server ensures consistent network access, crucial for servers and other always-on devices. This guide provides a step-by-step approach, covering both the command line and the NetworkManager GUI method. We'll also troubleshoot common issues.

Method 1: Setting a Static IP using Netplan (Command Line)

Netplan is the default network management tool in Ubuntu 20.04. This method uses a configuration file, offering better control and version management.

Step 1: Identify Your Network Interface

First, determine your server's network interface name. Use this command:

ip a

Look for the interface connected to your network (e.g., eth0, enp0s3, wlan0). Note the name; you'll need it in the next steps.

Step 2: Locate the Netplan Configuration File

The Netplan configuration file is usually located at /etc/netplan/. There's typically only one .yaml file; the name might include your server's hostname. For instance, it could be 01-network-manager-all.yaml or similar. You can list the files using:

ls /etc/netplan/

Step 3: Edit the Netplan Configuration File

Use your preferred text editor (like nano or vim) to open the configuration file:

sudo nano /etc/netplan/<your_config_file>.yaml

Replace <your_config_file> with the actual filename.

Step 4: Configure Static IP Settings

Within the file, you'll find a section for your network interface. Modify it to include your static IP settings. Below is an example. Adjust the values to match your network configuration.

network:
  version: 2
  renderer: networkd
  ethernets:
    <your_interface_name>: # Replace with your interface name (e.g., enp0s3)
      dhcp4: no
      addresses: [ <your_static_ip>/<subnet_mask> ] #Example: 192.168.1.100/24
      gateway4: <your_gateway> # Example: 192.168.1.1
      nameservers:
          addresses: [<your_dns_server>] # Example: 8.8.8.8, 8.8.4.4
  • <your_static_ip>: Your desired static IP address.
  • <subnet_mask>: Your subnet mask (e.g., 24, 16, etc.).
  • <your_gateway>: Your default gateway IP address.
  • <your_dns_server>: Your DNS server IP address(es). You can use Google's public DNS (8.8.8.8 and 8.8.4.4) if needed.

Save and close the file.

Step 5: Apply the Changes

Apply the new configuration:

sudo netplan apply

Step 6: Verify the IP Address

Check if the static IP is applied correctly using:

ip a

You should now see your static IP address assigned to the interface.

Method 2: Using the NetworkManager GUI (Graphical User Interface)

If you have a desktop environment installed, NetworkManager provides a graphical way to set a static IP.

  1. Open Network Settings: This varies depending on your desktop environment. Look for a network icon in your system tray or search for "Network Settings".

  2. Select Your Connection: Choose the wired or wireless connection you want to configure.

  3. Edit Connection: Click "Edit" or a similar option.

  4. Configure IPv4 Settings: Switch from "Automatic (DHCP)" to "Manual". Enter your static IP, netmask, gateway, and DNS server addresses.

  5. Save Changes: Save the changes and apply them.

  6. Verify the IP Address: Check your IP address using ip a in the terminal.

Troubleshooting

  • Failed to apply Netplan: Check for syntax errors in your .yaml file. Even a small mistake will prevent netplan apply from working.

  • IP address conflicts: Ensure the chosen IP address isn't already in use on your network.

  • No internet connectivity: Verify your gateway, DNS server settings, and that your network cables are properly connected. Also check your firewall rules.

This guide should help you successfully configure a static IP address on your Ubuntu 20.04 server. Remember to replace the placeholder values with your actual network details. Always back up your configuration files before making any changes.

Related Posts


Popular Posts