Friday 11 September 2015

"Network is unreachable" with Red Hat Enterprise Linux

I had a PEBCAK moment earlier this evening.

I was trying to work out why I was getting: -

Network is unreachable

when I was trying to contact ( ping ) a host external to my Red Hat Enterprise Linux VM.

The VM is running under VMware Fusion on my Mac, and I'm using Network Address Translation (NAT).

I have a static IP address that falls into the subnet of my Mac's external WiFi network, configured as follows: -

cat /etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.33.100
NETMASK=255.255.255.0
BROADCAST=192.168.33.255


I'd already checked the DNS configuration for my VM: -

cat /etc/resolv.conf 

; generated by /sbin/dhclient-script
search localdomain uk.ibm.com
nameserver 192.168.33.2


However, when I switched back to using DHCP: -

cat /etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

I got an IP address in the same subnet.

So it's NOT the address, and it's not the DNS configuration.

So what can it be, I hear you cry ?

Yep, you've guessed it :-)

I'd FORGOTTEN to set the default gateway :-)

For a static IP address, this needs to be set in one of two places.

For me, I did it thusly: -

cat /etc/sysconfig/network-scripts/ifcfg-eth0 

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.33.100
NETMASK=255.255.255.0
BROADCAST=192.168.33.255
GATEWAY=192.168.33.2

which sets it for that particular interface - eth0.

I could've set it globally as follows: -

cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=bpm856.uk.ibm.com
GATEWAY=192.168.33.2

Thanks to Google for pointing me in the right direction : -



No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...