2

I have a dynamic IP through DHCP.

I've edited the /etc/network/interfaces file to this:

# This file describes the network interfaces available on your system
 and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp1s0
iface enp1s0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1
        dns-nameservers 192.168.0.1 0.0.0.0

And I've tried the following commands:

  • systemctl restart ifup@enp1s0
  • systemctl restart ifup@eth0
  • sudo service network-manager restart

but none of them do what I want them to do, after entering ifconfig I keep seeing my dynamic IP of 192.168.0.30 coming up... What am I doing wrong?

(I'm ssh'ing into the machine using the dynamic IP address and for now I have a portforwarding rule based on the old rule, but I'd really like to have it static. I've chosen 200 to be waaaay out of range for anyone else to snatch it up).

1 Answer 1

2

You have to flush your current ip settings (DHCP based) and restart the networking service (or reboot) to make the settings apply correctly.

  • Running sudo ip addr flush enp1s0 on your terminal you can flush your current ip settings.

  • You can restart the networking service by running sudo systemctl restart networking.service on your terminal.

If you are running from a remote ssh session, maybe its better to run them in a single statement, like sudo ip addr flush enp1s0 && sudo systemctl restart networking.service, to avoid lossing conection at the middle of the process without restarting networking service (and setting up the new ip). Then you'll have to update you port forwarding rule on your router to be able to connect on the new (static) ip.

As a footnote, also keep in mind that some routers doesn't provide a true DNS service at all (they provide ISP's DNS ip address via DHCP), so I'll suggest to add Google's DNS open server (or other of your choice, maybe on your LAN) at least as secondary nameserver, for somehow failover pruposes due to the possible inability of your router.

Example:

auto enp1s0
iface enp1s0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        network 192.168.0.0
        gateway 192.168.0.1
        broadcast 192.168.0.255
        dns-nameservers 192.168.0.1
        dns-nameservers 8.8.8.8

Hope it helps.

1
  • After reinstalling the OS (again) because I entered the first command without reading further, and then setting the file up the same and running both commands at the same time, I finally saw it pop up under the new IP. Thanks!
    – Diamundo
    Jan 27, 2017 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.