I frequently build centos7 servers and have a few special networking requirements. For example, I may want to use nameservers or repositories in private ranges that can't be reached via my normal subnet or default gateway.

Imagine a kickstart with something like the following:

network --device eth0 --bootproto static --ip --netmask --gateway --nameserver

repo --name="private" --baseurl=

It's a purely theoretical setup. The theoretical box has an ip address in 192.168 range, with a default gateway that can reach the wider world, but would like to reach the 10/8 network and 172.16/12

Additionally, imagine that the default gateway cannot reach these other subnets.

On a live centos environment I could do the following

ip route add via

ip route add via

and to make persistent, this could be added to /etc/sysconfig/network-scripts/route-eth0

How do I get all this to come into play in anaconda? Historically this may have worked in %pre, but if I ssh into anaconda while it is running I can see that these routes are not in place.


Why don't you just set up the static routes in %post?

cat > /etc/sysconfig/network-scripts/route-eth0 <<EOF via via

If you need the static routes during installation, you can certainly add the appropriate ip route commands to %pre as well.

  • %post works fine and isn't a problem, however %pre will not work as you suggest (centos7 onwards). I thought the difference between network.service and NetworkManager.service could be rectified by adding entries in the format ADDRESS0=\nNETMASK0=\nGATEWAY0= but this also doesn't work. – Jarrod Jan 7 '19 at 18:16
  • I did have some luck though trying something from Fedora documentation: nmcli connection modify eth0 +ipv4.routes ipv4.gateway as anaconda did now have a route for, but sadly it didn't have a gateway. I must be close now! – Jarrod Jan 7 '19 at 18:23
  • Check the kickstart log file for the %pre section, to see what might have happened. – Michael Hampton Jan 7 '19 at 18:34
  • Good suggestion. I added a dummy package "deliberate-breaker" to my kickstart so anaconda would halt. In another tmux window I read the pre-install log. There were no errors relating to the ip route commands but the nmcli command did produce some output Error: Failed to modify connection 'eth0': ipv4.gateway: gateway cannot be set if there are no addresses configured, this suggests I need to define eth0 via nmcli first to progress further. – Jarrod Jan 8 '19 at 17:05
  • Is the interface actually named eth0? – Michael Hampton Jan 8 '19 at 17:12

I eventually found the solution

nmcli connection modify "System eth0" +ipv4.routes ""

This both works for the build, but also then stays persistent for afterwards

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.