Static Ip For Ubuntu
Method 1: Using Netplan
If ubuntu is using netplan:
Edit the Netplan YAML configuration file.
$ sudo nano /etc/netplan/*.yaml
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
After editing, apply the changes:
$ sudo netplan apply
Check the new IP address:
$ ip addr show enp0s3
Method 2: Using /etc/network/interfaces
If ubuntu is using interface, we configure your IP by editing the /etc/network/interfaces file.
$ sudo nano /etc/network/interfaces
Here is a basic static IP configuration:
auto enp0s3
iface enp0s3 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Restart the networking service to apply changes:
$ sudo /etc/init.d/networking restart
Advanced Configuration
For a more advanced configuration, you can set multiple static IPs or configure VLANs. For instance, configuring a secondary IP address:
auto enp0s3
iface enp0s3 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
iface enp0s3:1 inet static
address 192.168.1.101
netmask 255.255.255.0
To configure a VLAN:
auto enp0s3.10
iface enp0s3.10 inet static
address 192.168.2.100
netmask 255.255.255.0
vlan-raw-device enp0s3