LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Tuesday, January 10, 2023

How to set static IP address on Debian/Ubuntu Linux

0 comments
The first thing you must do is locate the name of your network device, DHCP IP address and default Gateway. For that, issue the commands and note down.

To find network interface

ip -c link show

You should at least see two devices, lo (for loopback) and another named device (such as enp0s3).

To find IP address

hostname -I

To find Gateway

ip route | grep default

Next, let’s back up the current network configuration file with the command:

sudo cp /etc/network/interfaces ~/

Open the configuration file for editing with the command:

sudo nano /etc/network/interfaces

With the interfaces file open for editing, you should see a DHCP configuration that looks like this:

# The primary network interface
allow-hotplug enp3s0
iface enp3s0 inet dhcp

Comment that block out so it looks like this:

# The primary network interface
# allow-hotplug enp3s0
# iface enp3s0 inet dhcp

Now, we can add the necessary configuration for a static IP address. Let’s configure enp0s3 to use the address 192.168.0.2, with a gateway of 192.168.0.1, and a DNS nameserver of  8.8.4.4 8.8.8.8 That configuration will look like this:

# The primary network interface
auto enp3s0
iface enp3s0 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.4.4 8.8.8.8

Make sure to edit the above configuration to match your network scheme. Save and close the file.

Finally, restart the networking service with the command:

sudo systemctl restart networking

Make sure the networking configuration is correct, by issuing the command:

hostname -I

You should see the static IP address you configured. You’re good to go.

No comments:

Post a Comment