0

As a matter of study I'm using VirtualBox with Debian 8 to learn basics of networking with the interface in bridge mode.

I deactivated dhcp of my network interface eth0 on /etc/network/interfaces:

# ...
# iface eth0 inet manual

Now I'm configuring the interface by my own:

# ifconfig eth0 192.168.0.99/24

And then, I test my gateway (which is 192.168.0.1) with ping and it works perfectly.

Then I add the default gateway to my routes table:

# route add default gateway 192.168.0.1 netmask 255.255.255.0 dev eth0

After some tests, downloads, etc. I see that everything is OK.

Then decided to learn how to delete routes and tested it with my default gateway. It works.

Here is my problem

After trying to add my gateway again with the same line above I got the "SIOCADDRT: Network is unreachable" error.

What I tried to solve?

  1. ifdown and ifup my interface;
  2. Reconfigure the interface with ifconfig;
  3. Restarting the networking daemon.

The only thing that works is restarting the machine.

Is there a way to add my route again without the need of restarting the machine?

  • please post the result of the command route to check – Noel Carcases Jan 28 '17 at 23:16
  • After I delete, route lists nothing. – juniorgarcia Jan 29 '17 at 3:12
  • To delete de default route the command should be route del default gw 192.168.0.1 after that you should still have one route the one corresponding to the interface route if you don't have that route you can add it manually route add 192.168.0.0/24 dev eth0 – Noel Carcases Jan 29 '17 at 12:24
0

I have reproduced your question on my own server

The important thing to note is that its not necessary to add a route to the network because the interface configuration do that for you. Even if you need to make this changes permanent you will put it on /etc/network/interfaces and with the "gateway" option specify the gateway for your network. That way you dont even has to add a default gw route for your network.

Setup: Home PC -> added a static ip 192.169.3.2 the goal is to reach that ip from a server connected on the same switch (virtual switch or physical switch is the same)

Server initial config

root@raspberrypi:~# ifconfig -a
eth0      Link encap:Ethernet  HWaddr b8:27:eb:fd:73:1b
          inet addr:192.169.1.2  Bcast:192.169.1.255  Mask:255.255.255.0
          inet6 addr: fe80::d89e:52c:aa96:d2b5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3883499 errors:0 dropped:46 overruns:0 frame:0
          TX packets:5939416 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:580337982 (553.4 MiB)  TX bytes:1486713518 (1.3 GiB)

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:370 errors:0 dropped:0 overruns:0 frame:0
          TX packets:370 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:29124 (28.4 KiB)  TX bytes:29124 (28.4 KiB)



root@raspberrypi:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
link-local      *               255.255.0.0     U     202    0        0 eth0
192.169.1.0     *               255.255.255.0   U     0      0        0 eth0

I will create now an interface to get the pc ip (192.169.3.2)

Interface creation and verification

    root@raspberrypi:~# ifconfig eth0:1 192.169.3.5/24
    root@raspberrypi:~# ifconfig eth0:1
    eth0:1    Link encap:Ethernet  HWaddr b8:27:eb:fd:73:1b
              inet addr:192.169.3.5  Bcast:192.169.3.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

Pinging my home pc without adding any routes

    root@raspberrypi:~# ping 192.169.3.2
    PING 192.169.3.2 (192.169.3.2) 56(84) bytes of data.
    64 bytes from 192.169.3.2: icmp_seq=1 ttl=128 time=32.3 ms
    64 bytes from 192.169.3.2: icmp_seq=2 ttl=128 time=2.95 ms
    ^C
    --- 192.169.3.2 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1001ms
    rtt min/avg/max/mdev = 2.956/17.642/32.329/14.687 ms

Checking actual routing table

    root@raspberrypi:~# route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    link-local      *               255.255.0.0     U     202    0        0 eth0
    192.169.1.0     *               255.255.255.0   U     0      0        0 eth0
    192.169.3.0     *               255.255.255.0   U     0      0        0 eth0

As you can see the route 192.169.3.0/24 trough interface eth0 has automatically been added to the routing table if I delete that route I will not have access to that network and will not be able to add a default route trought that network

Deleting the route and checking reachablity

root@raspberrypi:~# route del -net 192.169.3.0/24 dev eth0 
root@raspberrypi:~# route
root@raspberrypi:~# ping 192.169.3.2
PING 192.169.3.2 (192.169.3.2) 56(84) bytes of data.
^C
--- 192.169.3.2 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1005ms

Checking the interface configuration

root@raspberrypi:~# ifconfig eth0:1
eth0:1    Link encap:Ethernet  HWaddr b8:27:eb:fd:73:1b
          inet addr:192.169.3.5  Bcast:192.169.3.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

As you can see the interface is correctly configured but the network is not reachable because I have manually deleted that route from routing table... so kernel does not know where to send the package

Checking routing table

root@raspberrypi:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
link-local      *               255.255.0.0     U     202    0        0 eth0
192.169.1.0     *               255.255.255.0   U     0      0        0 eth0
root@raspberrypi:~#

If I manually add the route again the network will be reachable and I will be able to ping.

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.