Fedora Linux Support Community & Resources Center
  #1  
Old 2nd February 2012, 03:43 AM
Speeddymon Offline
Registered User
 
Join Date: Oct 2010
Posts: 18
windows_7firefox
Static routes with NetworkManager

I've been wrestling with this for hours now. I found some solutions that will work but I want an answer as to if I'm just doing it wrong in the first place, or if NetworkManager really is that much of a piece...

I have a VM running F16. The host is a Windows box on my corporate network. My host machine is in one city, I am in another. The machine I'm sitting at right now is on the company's lan, as is the host machine. I CAN ping the host and remote desktop to it. I could NOT ping or ssh to the guest. My colleague in the desk next to where my host machine is COULD ping the guest. This means it is a routing issue on the guest, since the office I'm in can't reach it, but can reach the host and someone in the same office where the guest is can reach it.

That being said, I manually setup the static routes through the command line. They work beautifully. I went to google to see if there was something in /etc/sysconfig/network-scripts which would do the static's automatically at boot. There is ... if you don't use NM.

I seem to encounter a bug when I try to add certain (valid) static routes through the GUI though.

Code:
[root@blackhole ~]# ip route show dev eth2
default via 10.36.0.1 
10.36.0.0/20  proto kernel  scope link  src 10.36.3.63  metric 1 
10.36.0.1  scope link 
[root@blackhole ~]# route -n |awk '/Dest|eth2/ {print}'
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.36.0.1       0.0.0.0         UG    0      0        0 eth2
10.36.0.0       0.0.0.0         255.255.240.0   U     1      0        0 eth2
10.36.0.1       0.0.0.0         255.255.255.255 UH    0      0        0 eth2
The network assigns the second line automatically. I can add the third line without issues through the GUI, however when I try to add the default route (first line), the OK button becomes disabled.

Now, my config is a bit unusual in that the corporate network should be adding the route properly via DHCP, but it is not. This is probably due to the fact that my eth2 in this VM is a bridged adapter rather than NAT. eth0 is NAT and works fine for outbound use but regardless of which office I'm in, I cannot ping into it, which means I cannot ssh into the VM through it. eth1 is a host-only adapter, so that I don't have to go out to the network when I'm just ssh'ing from the host to the guest (good for headless mode). So I had to setup this third adapter to bridge my host NIC with the guest to allow inbound access.

The problem is compounded by the fact that NM is pretty much required because I can't find documentation on the proper way to get networking going without it (in F16.. In F15 and before, I would disable NM and setup /etc/sysconfig/network-scripts/ifcfg-eth[0-2] but that doesn't seem to work properly now.

So I wanted to document 2 ways I've found to setup static routes which include a default gw for the static subnet when that default gw is not added by DHCP:

The first way is to create a script in /etc/NetworkManager/dispatcher.d:
Quote:
Originally Posted by theflier13 View Post
try the following as root:

touch /etc/NetworkManager/dispatcher.d/02-setuproutes
Code:
echo "#!/bin/sh

if [[ $2 == "up ]]
then
       ip r a default via 10.1.1.1 dev wlan0
fi" >> /etc/NetworkManager/dispatcher.d/02-setuproutes
chmod +x /etc/NetworkManager/dispatcher.d/02-setuproutes
/etc/init.d/NetworkManager restart

This creates a script that Network Manager will call every time your network devices either go up or down. NetworkManager calls this script and passes it the interface as the first argument and what is happening to it as the second argument (up/down).
Quote:
Originally Posted by ormsky View Post
Thanks for the reply. Initially, I had the file as:

#!/bin/sh
if [ "$2" = "up" ]
then
ip r a default via 10.1.1.1 dev wlan0
fi


but this didn't work. I added some echo commands which piped some output into a log file to check that it was getting called by Networkmanager, and this showed it was getting called but my route was not being added. I'd almost decided this wasn't going to work until I tried piping the error output for the ip command; this showed the error "command not found"! So I changed the file to:

#!/bin/sh
if [ "$2" = "up" ]
then
/sbin/ip r a default via 10.1.1.1 dev wlan0
fi

and now it works!!!
Cheers!
This works great if you aren't using DHCP (didn't test it on my config as I found what seems to be a less hackish way of doing it with dhcp). /etc/dhcp/dhclient.d/*.sh gets called by /etc/NetworkManager/dispatcher.d/11-dhclient already and so borrowing the format from /etc/dhcp/dhclient.d/chrony.sh, I was able to come up with the following.

/etc/dhcp/dhclient.d/route.sh:
Code:
!/bin/bash

route_config() {
        /sbin/route add -host 10.36.0.1 dev eth2
        /sbin/route add -net 0.0.0.0 gw 10.36.0.1 netmask 0.0.0.0 dev eth2
        exit 0
}

route_restore() {
        exit 0
}
Cheers in case anyone else finds this useful.
Reply With Quote
Reply

Tags
networkmanager, routes, static

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static routes aren't added after editing routes-wlan0 dobbi Servers & Networking 2 8th May 2011 01:51 PM
Static Routes ? grayboots Servers & Networking 4 16th February 2009 04:24 PM


Current GMT-time: 02:22 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Tacarigua - Nyagan Travel Photos - Leh Photos on Instagram