2.2 - Configure Networking

Configure Networking

  1. Find out your server's current IP address by logging in to your server and running the command:
    ifconfig

  2. Go to the Netplan configuration directory and open your network config file. Depending on how you installed Ubuntu, this could be 01-netcfg.yaml, 50-cloud-init.yaml, or something else.
    cd /etc/netplan
    sudo joe 50-cloud-init.yaml
    
  3. The contents of the file will look something like this:
    network:
        ethernets:
            enp0s3:
                addresses: []
                dhcp4: true
        version: 2
    

    This is a DHCP (automatic IP) setup on the network interface "enp0s3". Change it to look something like this (will vary depending on your network setup):

    network:
        ethernets:
            enp0s3:
                addresses: [10.10.1.99/24]
                gateway4: 10.10.1.1
                dhcp4: false
                nameservers:
                    addresses: [8.8.8.8,8.8.4.4]
        version: 2
    

    The above sample configuration would give your server the address 10.10.1.99. The gateway of your network can be anywhere but is generally at address "1" of the range. The DNS nameservers configured here are Google's. You may have different DNS servers to input instead.

    Note: As this file is a YAML file, indentation is important. If you do not indent the lines so that they are in a correct hierarchy as above, you will receive an error when running the commands below.
     

  4. Apply the networking changes
    sudo netplan apply
    
  5. You should now be able to access your server. You can run
    ifconfig

    to confirm the IP has changed.