Konfigurasi IP Static di Ubuntu 18.04

ubuntu logo

Rekan-rekan yang sudah sering melakukan installasi Server dengan Sistem Operasi Ubuntu versi sebelumnya, mungkin akan bingung ketika ingin melakukan konfigurasi IP Static di Ubuntu 18.04. Hal tersebut dikarenakan Ubuntu 18.04 menggunakan Netplan untuk manajemen networknya. Seperti yang kita ketahui bersama, pada versi sebelumnya untuk konfigurasi network letak konfigurasinya ada di dalam file /etc/network/interfaces.

Konfigurasi IP static

Contoh kita ingin melakukan konfigurasi network seperti berikut:

  • IP static : 192.168.1.93
  • Netmask: 255.255.255.0
  • Gateway: 192.168.1.1
  • DNS: 202.73.99.4, 202.73.99.2, 111.95.141.4 (DNS dari ISP)

Setelah login ke server sebagai user biasa, login dulu sebagai user root:

user@server:~$ sudo su
[sudo] password for user:

Lakukan backup file konfigurasi defaultnya:

# cd /etc/netplan/
# rsync -auvr 50-cloud-init.yaml 50-cloud-init.yaml_backup

Buka file konfigurasinya:

# vi 50-cloud-init.yaml

Edit file sesuai dengan data yang diberikan sebelumnya

# 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:
    ens160:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.1.93/24]
      gateway4: 192.168.1.1
      nameservers:
          search: [kelolaserver.com]
          addresses: [202.73.99.4, 202.73.99.2, 111.95.141.4]

Notes:
File tersebut menggunakan format YAML, jadi gunakan space untuk mengatur jarak konfigurasinya dan bukan menggunakan Tab ya.

Simpan file konfigurasinya dan jalankan perintah berikut:

# netplan apply

Apabila menemukan error, coba jalankan perintah berikut untuk pengecekan lebih detil:

# netplan --debug apply

Konfigurasi selesai, jangan lupa lakukan pengecekan dan testing network:

Cek IP

root@server:/etc/netplan# ifconfig 
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.93 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::20c:29ff:fedc:68a5 prefixlen 64 scopeid 0x20<link>
inet6 fdfb:fc3c:7dea:0:20c:29ff:fedc:68a5 prefixlen 64 scopeid 0x0<global>
ether 00:0c:29:dc:68:a5 txqueuelen 1000 (Ethernet)
RX packets 11917 bytes 1711175 (1.7 MB)
RX errors 0 dropped 5 overruns 0 frame 0
TX packets 1672 bytes 214502 (214.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 216 bytes 17192 (17.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 216 bytes 17192 (17.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Cek rute gateway

root@server:/etc/netplan# route -N
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 ens160
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160

Cek nameserver/dns

root@server:/etc/netplan# cat /etc/resolv.conf 
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
search kelolaserver.com

Cek nslookup

root@server:/etc/netplan# nslookup google.com
Server: 127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
Name: google.com
Address: 74.125.24.102
Name: google.com
Address: 74.125.24.100
Name: google.com
Address: 74.125.24.138
Name: google.com
Address: 74.125.24.139
Name: google.com
Address: 74.125.24.113
Name: google.com
Address: 74.125.24.101
Name: google.com
Address: 2404:6800:4003:c04::65

Kalau hasil pengecekan sudah OK, server Ubuntu 18.04 siap untuk digunakan.

Sekian dan terima kasih, semoga bermanfaat ya.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top