he procedure is as follows to set up and configure a static IP information:
- Open the terminal application.
- Log in to remote or server using ssh command.
- Backup /etc/network/interfaces file running sudo cp /etc/network/interfaces /root/
- Edit the /etc/network/interfaces
- Configure static IP address for enp0s5 Ethernet interface: address 192.168.2.249
- Add subnet mask: netmask 255.255.255.0
- Set up default gateway IP: gateway 192.168.2.254
- Finally add DNS resolver IP: dns-nameservers 192.168.2.254 8.8.8.8 1.1.1.1
Let us see all commands and examples in details.
Finding your network interfaces name on Debian
Show available ethenet network interfaces:
| root@debian:/etc/network# ip -c link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:1d:62:ad brd ff:ff:ff:ff:ff:ff altname enp2s1
|
Show the current IP address assinged to that network interface:
| root@debian:/etc/network# ip -c addr show ens33 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:1d:62:ad brd ff:ff:ff:ff:ff:ff altname enp2s1 inet 2.1.1.131/24 brd 2.1.1.255 scope global dynamic ens33 valid_lft 1322sec preferred_lft 1322sec inet6 fe80::20c:29ff:fe1d:62ad/64 scope link valid_lft forever preferred_lft forever
|
Configuring Static IP on Debian
The /etc/network/interfaces[/file] contains network interface configuration information for Debian Linux.
| nano /etc/network/interfaces
|
Look for the primary network interface ens33, remove dhcp and allow-hotplug lines.
| auto lo iface lo inet loopback
auto ens33 iface ens33 inet static address 2.1.1.129 netmask 255.255.255.0 gateway 2.1.1.2
dns-nameservers 2.1.1.2
|
Restart networking service on Debian
| systemctl restart networking.service systemctl status networking.service
|
Check the new IP address assigned on Debian
| ip -c addr show ip -c addr show ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:1d:62:ad brd ff:ff:ff:ff:ff:ff altname enp2s1 inet 2.1.1.129/24 brd 2.1.1.255 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe1d:62ad/64 scope link valid_lft forever preferred_lft forever
|
Another Way for All Linux Distros (*)
| nmcli device
nmcli connection modify ens33 ipv4.addresses 2.1.1.130/24 nmcli connection modify ens33 ipv4.gateway 2.1.1.2 nmcli connection modify ens33 ipv4.dns 2.1.1.2 nmcli connection modify ens33 ipv4.method manual
nmcli connection down ens33 && nmcli connection up ens33
|