25

I think I have a routing problem. I have set up a CentOS VM, it is connected to my network and I can ping other machines.

I cannot however ping anything outside of my network.

[root@localhost ~]# ping 8.8.8.8
connect: Network is unreachable

I also set up port forwarding on my router to forward SSH on port 22 to this machine and I cannot access it outside of my network (using putty).

Here is the output of ip route:

[root@localhost ~]# ip route
10.0.0.0/24 dev enp0s3  proto kernel  scope link  src 10.0.0.10
169.254.0.0/16 dev enp0s3  scope link  metric 1002

Here is the contents of /etc/sysconfig/network-scripts/ifcfg-enp0s3:

TYPE="Ethernet"
BOOTPROTO="static"
IPADDR=10.0.0.10
NETMASK=255.255.255.0
NM_CONTROLLED=no
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="enp0s3"
UUID="17eeb7fe-f11c-4b8b-83be-a9dd2281dda2"
DEVICE="enp0s3"
ONBOOT="yes"
2
  • You appear to be missing a default route. So your machine only knows how to get to 10.0.0.* addresses. Assuming a default .1 for the gateway, you can add GATEWAY=10.0.0.1 to the file.
    – Ciclamino
    Apr 15, 2015 at 1:02
  • 1
    can you post the contents of /etc/sysconfig/network and /etc/resolv.conf
    – td512
    Apr 15, 2015 at 1:04

4 Answers 4

22

Based on the errors, you need to update the files to look like this:

/etc/sysconfig/network-scripts/ifcfg-enp0s3:

TYPE="Ethernet"
BOOTPROTO="static"
IPADDR=10.0.0.10
NETMASK=255.255.255.0
NM_CONTROLLED=no
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="enp0s3"
UUID="17eeb7fe-f11c-4b8b-83be-a9dd2281dda2"
DEVICE="enp0s3"
ONBOOT="yes"

/etc/sysconfig/network:

NETWORKING=yes
HOSTNAME=centos7
GATEWAY=10.0.0.1

/etc/resolv.conf:

nameserver 8.8.8.8
nameserver 8.8.4.4
4
  • 1
    While there's nothing wrong with that resolv.conf, it's not needed to fix the routing.
    – Ciclamino
    Apr 15, 2015 at 1:16
  • true, but it will help for resolving domain names if that functionality is needed
    – td512
    Apr 15, 2015 at 1:24
  • I'm actually using the DNS servers provided by my ISP, I was just testing with 8.8.8.8 as it's easier to remember.
    – Neilos
    Apr 15, 2015 at 1:43
  • 1
    I had actually thought that it was a problem with the gateway not being specified (it is indeed 10.0.0.1). I just wasn't sure enough to actually take myself seriously. It works now. Thank you very much.
    – Neilos
    Apr 15, 2015 at 1:47
8

Add this command:

route add default gw [your gateway IP address]
2
  • 2
    that resolved it for me. i had switched gateways, made adjustments to ifcfg, set link down, then back up, no internet. this got the internet back. thanks! Mar 7, 2020 at 0:22
  • this should be the correct answer IMHO. Jun 21, 2020 at 16:02
0

why don't you just change it to dhcp, look for a proper IP and then set it to static with that IP?

1
  • that's a downgraded experience when you are dealing with servers, and not future proof at all. you want to design a network and rely on clear network documentation. Jun 21, 2020 at 16:03
-1

Add a default gateway

# route add default gw 10.0.0.10 enp0s3
1
  • 4
    That’s not a permanent solution. And neither is his own PC the gateway.
    – Daniel B
    Nov 4, 2015 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .