본문 바로가기
컴퓨터 활용(한글, 오피스 등)/50_2.운영체제_리눅스

리눅스_Ubuntu Static IP configuration

by 3604 2022. 11. 15.
728x90

Ubuntu Static IP configuration

출처: https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-10-cosmic-cuttlefish-linux

This tutorial will deal with Ubuntu static IP address configuration. It will provide the reader with a step by step procedure how to set static IP address on Ubuntu Server via netplan and Ubuntu Desktop using NetworkManager. Static IP address is recommended for servers as the static address does not change as oppose to a dynamic IP address assignment via DHCP server.

This tutorial will work for all recent versions of Ubuntu, including the latest LTS release, Ubuntu 22.04 Jammy Jellyfish. Ubuntu offers us a GUI method and command line method to set a static IP address, and both methods are covered below.

DID YOU KNOW?
Did you know that static IP address can also be achieved by DHCP server? DHCP server allows for a manual MAC address binding to a specific IP address, which will result in client receiving same static IP address with each dynamic IP address request.

In this tutorial you will learn how to:

  • Set static IP address on Ubuntu Desktop using a NetworkManager
  • Configure static IP address on Ubuntu server via networkd daemon

 

Ubuntu Static IP configuration

Software Requirements and Conventions Used

Software Requirements and Linux Command Line ConventionsCategoryRequirements, Conventions or Software Version Used

System Installed or Ubuntu Server/Desktop
  N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Ubuntu Static IP configuration step by step

Ubuntu Desktop

The simplest approach on how to configure a static IP address on Ubuntu Desktop is via GNOME graphical user interface:

  1. Click on the top right network icon and select settings of the network interface you wish to configure to use a static IP address on Ubuntu.
    Open network settings Ubuntu Desktop

  2. Click on the settings icon to start IP address configuration.
    Start network configuration to set static IP address
  3. Select IPv4 tab.
    Static IPv4 IP address Ubuntu Desktop
  4. Select manual and enter your desired IP address, netmask, gateway and DNS settings. Once ready click Apply button.
    Enter your desired static IP address

  5. Turn OFF and ON switch to apply your new network static IP configuration settings.
    Apply your new network configuration settings
  6. Click on the network settings icon once again to confirm your new static IP address settings.
    Confirm your new IP address settings

Ubuntu Server

To configure a static IP address on your Ubuntu server you need to modify a relevant netplan network configuration file within /etc/netplan/ directory.

NOTE
Carefully check the renderer stanza in your configuration file. If the renderer configuration is set to NetworkManager then your Ubuntu’s system network configuration is managed by GUI Network Manager. Change the renderer to renderer: networkd if you do not wish to configure your network IP address via Graphical User Interface ( desktop ).

For example, you might find there a default netplan configuration file called 50-cloud-init.yaml or 01-network-manager-all.yaml with a following content using the networkd deamon to configure your network interface via DHCP:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
    version: 2



Default dynamic IP address settings on Ubuntu Server

To set your network interface enp0s3 to static IP address 192.168.1.233 with gateway 192.168.1.1 and DNS server as 8.8.8.8 and 8.8.4.4 replace the above configuration with the one below.

WARNING
Note, you must adhere to a correct code indent for each line of the block. In other words the prefix number of spaces for each line is important. Otherwise you may end up with an error message similar to:
Invalid YAML at //etc/netplan/01-netcfg.yaml line 7 column 6: did not find expected key
.
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
     dhcp4: no
     addresses: [192.168.1.233/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]
Ubuntu server configured with static IP address.

Once ready apply changes with:

$ sudo netplan apply

In case you run into some issues execute:

$ sudo netplan --debug apply
728x90