I want to have the ability to edit my static IP on Ubuntu 16.04 Desktop using only CLI. However, when I do that I have two IP addresses for the same machine: one is assigned by DHCP server and the other taken from /etc/network/interfaces.
Here's the process
Edited /etc/network/interfaces and added static IP. Contents of the file:
# 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
auto enp0s3
iface enp0s3 inet static
address 192.168.0.29
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4
Stopped and removed Ubuntu Network Manager:
sudo service network-manager stop
sudo apt-get purge network-manager
Restarted networking service:
sudo /etc/init.d/networking restart
Also tried to restart interface itself:
ifdown enp0s3 && ifup enp0s3
Tried to reboot the machine, didn't help either.
The result is that I have two IP addresses assigned to my machine. I even tried to ssh to both of them and it's really the same machine.. First one is assigned from DHCP server:
ping 192.168.0.189
PING 192.168.0.189 (192.168.0.189): 56 data bytes
64 bytes from 192.168.0.189: icmp_seq=0 ttl=64 time=0.341 ms
64 bytes from 192.168.0.189: icmp_seq=1 ttl=64 time=0.265 ms
64 bytes from 192.168.0.189: icmp_seq=2 ttl=64 time=0.315 ms
64 bytes from 192.168.0.189: icmp_seq=3 ttl=64 time=0.395 ms
Second one is assigned by editing /etc/network/interfaces
ping 192.168.0.29
PING 192.168.0.29 (192.168.0.29): 56 data bytes
64 bytes from 192.168.0.29: icmp_seq=0 ttl=64 time=0.380 ms
64 bytes from 192.168.0.29: icmp_seq=1 ttl=64 time=0.742 ms
64 bytes from 192.168.0.29: icmp_seq=2 ttl=64 time=0.313 ms
64 bytes from 192.168.0.29: icmp_seq=3 ttl=64 time=0.308 ms
ifconfig produces the same result before and after making the edits:
ifconfig -a
enp0s3 Link encap:Ethernet HWaddr 08:00:27:f6:b1:d3
inet addr:192.168.0.189 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13984 errors:0 dropped:0 overruns:0 frame:0
TX packets:1310 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2496671 (2.4 MB) TX bytes:124720 (124.7 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:252 errors:0 dropped:0 overruns:0 frame:0
TX packets:252 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:19145 (19.1 KB) TX bytes:19145 (19.1 KB)
So what is happening here?