4

Have following configuration in /etc/network/interfaces

auto enp1s0
iface enp1s0 inet static
  address 192.168.1.3
  netmask 255.255.255.0
  gateway 192.168.1.1
  mtu 1500
  dns-nameserver 8.8.8.8

After boot internet works.

Suppose one wants to change his address from 192.168.1.3 to 192.168.1.5

ifconfig enp1s0 192.168.1.5 netmask 255.255.255.0

But now internet does not work! Even if reset ip back to 192.168.1.3

ifconfig enp1s0 192.168.1.3 netmask 255.255.255.0

it does not connect to the internet, only after reboot it works again with specified in /etc/network/interfaces static address. I read man pages, tried various commands with ip, route, ifconfig - does not seem to help.

Could you please show how to solve the problem?

1

ifconfig only set IP address. To have internet access you need to specify a default gateway and DNS namesever. Use following commands:

ifconfig enp1s0 192.168.1.5 netmask 255.255.255.0
route add  default gw 192.168.1.1
echo "dns-nameserver 8.8.8.8" > cat /etc/resolv.conf
  • Interesting, I found that after every execution of ifconfig(setting netmask and static IP address) removes default gateway from routing tables, so one needs to reissue "route ... gw IP address"? What that happens? Very unusual for me. – Bulat M. Nov 23 '16 at 14:40
  • 1
    @BulatM. : Because you have configured enp1s0 to get IP address, subnet mask, default gateway IP address and DNS server IP address from DHCP Server. Issuing ifconfig command says to your Linux box to not using DHCP configuration, so default gateway record is removed from the routing table. – SuB Nov 23 '16 at 18:55
  • @SuB, I did not said that I used DHCP, indeed I was trying to get run with static configuration in that case. Could you point to man pages or another source where it stated that after ifconfig execution default route(gateway) gets removed from kernel's routing table? – Bulat M. Nov 23 '16 at 19:43
  • 1
    @BulatM. Sorry. DHCP/Static configuration have the same result when you set IP address using ifconfig. I haven't any resource says about this situation. – SuB Nov 23 '16 at 20:01
  • @SuB, could you please also explain the differences between purposes of NetworkManager(.service) and networking(.service). It is not clear why one needs the latter. – Bulat M. Nov 25 '16 at 17:37
1

After you edited the network configurations, run following command:

sudo systemctl restart networking
  • Could you please explain what is the difference between NetworkManager.service and networking service. First is daemon to make network configuration user-friendly but why do one need to use networking.service(and restart it)? – Bulat M. Nov 23 '16 at 14:38

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.