Server IP address & DNS

Updated on: 10.Dec.2020

The following is required if you are setting up Ubuntu outside of the cloud hosting. In cloud hosting, the public IP address will be assigned to you upon creating a new Droplet.

During the installation, I choose DHCP option to configure the server IP address. After the installation completed, assign a static IP address. 

In the command console:

          sudo nano /etc/network/interfaces

Then, add these settings:           

          iface eth0 inet static
          address 192.168.1.3
          netmask 255.255.255.0
          gateway 192.168.1.1
          dns-nameservers8.8.8.8 8.8.4.4

Install the ifupdown component,

           sudo apt install ifupdown

Press CTRL+X to save the changes. After that restart the networking service

          sudo ifdown -a
          sudo ifup -a

Start from Ubuntu version 16.04, you may use netplan to handle the network configuration. 

  •  First is to find out the configuration file and mine is 50-cloud-init.yaml.

    ls /etc/netplan

  • Then, edit the file with nano. The configuration should look like this (as per our server).
network:
    version: 2
    ethernets:
        eth0 :
            dhcp4: no
            addresses:
              - 192.168.1.3/24
            gateway4: 192.168.1.1
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
  • After updated the configuration, save the changes and run the following command
  sudo netplan apply
 
Notes on YAML configuration file:
  • No tab key in allowed. All indentation must be done with space key (usually 2 spaces).

Operation notes

  • To view the dynamic IP address assigned by DHCP server:

              ip addr | grep inet

  • To get the network settings,

   ip addr

  • To get the IP address, DNS and gateway for the dynamic IP, type the following command. Please take not that you have to replace "enp0s3" from the following command. Replace it with the interface ID with "ip addr".

   netplan ip leases enp0s3

  • If you want to find out just the DNS server:

   systemd-resolve --status

  • To find out the gateway:

   ip route

Sample output: below is my test server. It's IP address is 192.168.1.53 and the gateway is 192.168.1.1.

   default via 192.168.1.1 dev enp0s3 proto dhcp src 192.168.1.53 metric 100
   192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.53
   192.168.1.1 dev enp0s3 proto dhcp scope link src 192.168.1.53 metric 100

Reference

http://www.howtoforge.com/linux-basics-set-a-static-ip-on-ubuntu
https://linuxize.com/post/how-to-configure-static-ip-address-on-ubuntu-18-04/
https://netplan.io/faq/


 

 

 

 

 

 

 

 

 

 

 

No comments:

Post a Comment