1

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 192.168.0.100 --netmask 255.255.0.0 --gateway 192.168.0.1 --nameserver 10.0.0.100

repo --name="private" --baseurl=http://172.16.0.100/private/7/x86_64

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 10.0.0.0/8 via 192.168.0.2

ip route add 172.16.0.0/12 via 192.168.0.3

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.

2

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

%post
cat > /etc/sysconfig/network-scripts/route-eth0 <<EOF
10.0.0.0/8 via 192.168.0.2
172.16.0.0/12 via 192.168.0.3
EOF

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

10
  • %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=10.0.0.0\nNETMASK0=255.0.0.0\nGATEWAY0=192.168.0.2 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 10.0.0.0/8 ipv4.gateway 192.168.0.2 as anaconda did now have a route for 10.0.0.0/8, 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
1

I eventually found the solution

%pre
nmcli connection modify "System eth0" +ipv4.routes "10.0.0.0/8 192.168.0.2"
%end

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.