Network is unreachable

Issues related to configuring your network
Post Reply
jamesy281
Posts: 11
Joined: 2015/02/16 16:30:01

Network is unreachable

Post by jamesy281 » 2017/06/19 16:53:08

I am trying to set up a static route on my centos box so that traffic is pointed to a different gateway, but I am getting the error above. My set up is below. I have tried several different methods but I cannot get it to work.

IP address: 192.168.250.98/24
gateway:192.168.250.1 ==> default on switch, connected to MPLS router 1.1.1.1

We also have a firewall connected to the network with a LAN IP of 192.168.250.250 and WAN IP of 2.2.2.2.

when I try to connect to our AWS server via ssh with a custom port of 1234 on the primary connection (MPLS) it will not connect despite being allowed on AWS. (this also happened on a a windows instance and I added a static route with problem) so I added a static route on this Centos box:

ip route <aws_pub_ip> via 192.168.250.250 to which I receive network is unreachable. reading around I see the issue is caused by the next hop being on the same subnet as the default gateway and /or not being directly connected. So I tried adding the WAN IP of the firewall which I can ping but I get the same.

I have never come across something that was simple to do on Windows and not on Linux, this is a first. I would appreciate some help.

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Network is unreachable

Post by TrevorH » 2017/06/19 17:08:50

It's possible to add a more specific route to the system - e.g you can have default via 192.168.250.1 and 8.8.8.8 via 192.168.250.250. The only time you would get a network is unreachable is if you tried to create a route that was not accessible directly from your subnet. So with your interface having 192.168.250.98/24

ip ro add default via 192.168.250.1 <- works
ip ro add 8.8.8.8 via 192.168.250.250 <- works
ip ro add 8.8.8.9 via 192.168.251.1 <- network is unreachable
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

jamesy281
Posts: 11
Joined: 2015/02/16 16:30:01

Re: Network is unreachable

Post by jamesy281 » 2017/06/19 17:49:07

Hey Trevor,

I am adding a more specific route by saying aws-ip via 192.168.250.250. It is reachable via that path as I have added the same route to the windows box.

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Network is unreachable

Post by TrevorH » 2017/06/19 18:28:05

Without more specific information I think it's going to be difficult to help. Can you share the output from ip ro sh and the ip ro add that fails? It would be best if you showed us exactly what you're running in case you are obscuring some unnoticed typo by changing them before you post it...
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

jamesy281
Posts: 11
Joined: 2015/02/16 16:30:01

Re: Network is unreachable

Post by jamesy281 » 2017/06/20 09:40:59

The routing table is really simple:

default via 192.168.250.1 dev ens160 proto static metric 100
192.168.250.1 dev ens160 proto static scope link metric 100
192.168.250.98 dev ens160 proto kernel scope link src 192.168.250.98 metric 100

The command I enter is:

ip route add <remote-ip> via 192.168.250.250 and the result is:

RTNETLINK answers: Network is unreachable

192.168.250.250 is reachable from this interface as it is on the same subnet as is the public IP

jamesy281
Posts: 11
Joined: 2015/02/16 16:30:01

[Solved] Re: Network is unreachable

Post by jamesy281 » 2017/06/20 18:30:20

So my colleague gave me a second set of eyes and spotted pretty quickly that the net mask of the centos box was wrong. I'm not sure how (or how it worked) but the prefix in the ifcfg-eth0 was 32 instead of 24.

Thanks for the responses.

Post Reply