Skip to content

Instantly share code, notes, and snippets.

@fullmetalbrackets
Created August 3, 2023 03:20
Show Gist options
  • Save fullmetalbrackets/4cc132571a2663c481b7c197d3681c78 to your computer and use it in GitHub Desktop.
Save fullmetalbrackets/4cc132571a2663c481b7c197d3681c78 to your computer and use it in GitHub Desktop.
Set static IP in Debian

Make a backup copy of the default network interfaces file

cp /etc/network/interfaces /etc/network/default-interfaces

Edit the interfaces file

nano /etc/network/interfaces

Look for these lines, substituting enp0s1 for your own interface

allow-hotplug enp0s1
iface enp0s1 inet dhcp

Edit to this, substituting your own address, gateway, and dns-nameservers.

auto enp0s1
iface enp0s1 inet static
 address 192.168.1.100
 netmask 255.255.255.0
 gateway 192.168.1.1
 dns-nameservers 9.9.9.11 149.112.112.11

Save and close the file, restart the network interface

systemctl restart ifup@enp0s1

And restart the networking service

systemctl restart networking.service

Note: If you're using a different service to control networking, restart it instead --
e.g. systemctl restart NetworkManager.service

Now edit (or create) resolv config file

nano /etc/resolv.conf

Add your DNS resolvers into it

nameserver 9.9.9.11
nameserver 149.112.112.11

Confirm your IP is now static with this command

ip -c addr show enp0s1

The output should look something like this

2: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.1.100/24 brd 192.168.0.255 scope global enp0s1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment