# [solved] Network problems with Gentoo as KVM / virtio guest

## fberger

Hi,

I have been running a Gentoo server as a KVM guest with a cloud provider. So far I have 437 days uptime and no issues.

I now am trying to migrate that server to a different data center with the same provider. I took my usual course of action, which is:

attaching a new empty virtual drive to a temporary virtual server at the new location

rsyncing the old server to the new drive

chrooting

installing a boot loader

terminating the temporary virtual server

and firing up the new server.

The issue is that on the new server copy, I am unable to set up networking, i.e. setting a default route does not work.

I got a static IP and an associated default gateway from the cloud provider. I use /etc/conf.d/net for setup:

```
config_eth0="<IP>"

routes_eth0="default via <Gateway IP>"

dns_servers_eth0="<DNS IP> <DNS IP> <DNS IP>"
```

On the original virtual server, this works flawlessly.

On the new server, the device apparently boots up and gets assigned an IP, but there is a problem setting the default gateway:

```
* About to start the service net.eth0

* Bringing up interface eth0

*   Caching network module dependencies

*   <IP> ... [ok]

*   Adding routes

*     default via <Gateway IP> ... RTNETLINK answers: Network is unreachable

[ !! ]

[ !! ]
```

Subsequently, `ifconfig` shows eth0 as up and running with the IP assigned, but `route` shows no route, and adding yields:

```
$ route add default gw <Gateway IP>

SIOCADDRT: Network is unreachable
```

The underlying KVM uses a virtio setup to provide networking.

What baffles me is that the very same configuration is running flawlessly in the old datacenter.

I assume that the cloud provider uses the same software and setups across all the data centers.

I am not a very experienced network debugging person. Any hints how to approach this?Last edited by fberger on Sun Aug 20, 2017 7:25 pm; edited 2 times in total

----------

## mike155

Your provider should have given you 1) an IP address 2) a local net (typically a netmask) and 3) a gateway. The IP address of the gateway must be inside the local net. If it's not, you get the message "Network is unreachable". 

Check your interface settings and make sure that the gateway IP address is inside the local net of the interface.

----------

## NeddySeagoon

bug_report,

Or you need a static route to the gateway.

----------

## chiefbag

Are you sure your new vm has eth0 as the interface?

If you have synced the image from another machine you may be now on eth1 as there will already be a udev entry for the old MAC address as eth0.

----------

## szatox

 *Quote:*   

> I assume that the cloud provider uses the same software and setups across all the data centers. 

 Don't assume that. It's basically impossible to change an already deployed datacenter, so building a new datacenter is a good time to use all the knowledge you collected from your failures.

 *Quote:*   

>  default via <Gateway IP> ... RTNETLINK answers: Network is unreachable

 

You seem to have a wrong netmask. Can you set a route to your gateway manually?

Something like:

ip route add <gateway>/32 dev eth0

This command states your demands in a rather explicit way, so kernel shouldn't complain that it doesn't know what you tried to imply.

----------

## fberger

Hey, thanks for the hints.

 *bug_report wrote:*   

> Check your interface settings and make sure that the gateway IP address is inside the local net of the interface.

 

That was the first thing I checked. IP is x.y.z.239, gateway is x.y.z.1, so they should be on the same net.

 *chiefbag wrote:*   

> Are you sure your new vm has eth0 as the interface?
> 
> If you have synced the image from another machine you may be now on eth1 as there will already be a udev entry for the old MAC address as eth0.

 

As I can bring up eth0 with the given IP, I suspect the current virtual networking devices is registered as eth0.

Also, I can bring up eth0 with `ifconfig`, while I cannot bring up an eth1 this way.

 *szatox wrote:*   

> Don't assume that. It's basically impossible to change an already deployed datacenter, so building a new datacenter is a good time to use all the knowledge you collected from your failures.

 

True, but the provider explicitly advertises transfer of services between the datacenters, plus they all share the same web UI. It is possible, but not likely that the provider deploys different software below the virtual servers. I'll keep that investigation as a last resort, but I suspect the error to be somewhere else.

 *szatox wrote:*   

> You seem to have a wrong netmask. Can you set a route to your gateway manually?
> 
> Something like:
> 
> ip route add <gateway>/32 dev eth0
> ...

 

Setting that works, and yields

```
$ route -n

Kernel IP routing table

Destination  Gateway  Genmask          Flags  Metric  Ref  Use  Iface

x.y.z.1      0.0.0.0  255.255.255.255  UH     0       0      0  eth0

```

As a result, I can ping the gateway. And subsequently I can set a default route via that gateway and access the internet. Yay! Thanks!

Now I have to figure out how to set the netmask correctly, and get a persistant configuration for that.

----------

## fberger

Setting

```
config_eth0="<IP>/24" 
```

in /etc/conf.d/net solves the issue. Thanks a ton!

----------

