Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
VPNC & Default route
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
bastibasti
Guru
Guru


Joined: 27 Nov 2006
Posts: 590

PostPosted: Sat Nov 03, 2007 10:23 am    Post subject: VPNC & Default route Reply with quote

Hi there,

thus I dont know much about routing, I have to ask the question :D
I use VPNC to connect to the companies network, and it runs very well. The only thing that annoys me is that the default route is set to the tunnel device. Is that fixable somehow (statically)?
Back to top
View user's profile Send private message
tarpman
Veteran
Veteran


Joined: 04 Nov 2004
Posts: 1083
Location: Victoria, BC, Canada

PostPosted: Sat Nov 03, 2007 6:44 pm    Post subject: Reply with quote

I whipped together a small shell script to deal with exactly this case... I'll post it here when I get home.
_________________
Saving the world, one kilobyte at a time.
Back to top
View user's profile Send private message
bastibasti
Guru
Guru


Joined: 27 Nov 2006
Posts: 590

PostPosted: Sun Nov 04, 2007 9:24 am    Post subject: Reply with quote

That would be great!
Back to top
View user's profile Send private message
tylerwylie
Guru
Guru


Joined: 19 Sep 2004
Posts: 458
Location: /US/Georgia/Atlanta

PostPosted: Sun Nov 04, 2007 9:45 am    Post subject: Reply with quote

You can use the route command to set metrics on the routes, i.e your gateway as 1 and the tunnel's gateway as 2, and your gateway will be preferred.
Back to top
View user's profile Send private message
bastibasti
Guru
Guru


Joined: 27 Nov 2006
Posts: 590

PostPosted: Sun Nov 04, 2007 12:26 pm    Post subject: Reply with quote

I think the script deletes thze default route and restores it on disconnect.
Back to top
View user's profile Send private message
tarpman
Veteran
Veteran


Joined: 04 Nov 2004
Posts: 1083
Location: Victoria, BC, Canada

PostPosted: Mon Nov 05, 2007 3:44 am    Post subject: Reply with quote

So you have vpnc(8) set up, and /etc/init.d/vpnc start works, but you'd rather it didn't take over your entire connection every time, right? Here's the script I put together to constrain the takeover slightly. You'll of course have to fix IPs and possibly netmasks yourself. If you don't understand what some part of it does, please ask rather than just assuming it'll work for you. In the interests of convenience I have it modify my /etc/resolv.conf to use the company DNS servers, because I ssh and rdesktop into several machines there by name, but you don't need to use that if you'd rather not.

/usr/local/sbin/vpn:
#!/bin/sh

case "$1" in
    start)
       
        # start the tunnel
        modprobe tun
        /etc/init.d/vpnc start || exit $?

        # delete the default route added by vpnc
        route del default dev tun0

        # set up a narrower route
        route add -net 1.2.0.0 netmask 255.255.0.0 tun0

        # update resolv.conf
        cp /etc/resolv.conf /tmp/resolv.conf.orig
        echo "search company.com" > /etc/resolv.conf
        echo "nameserver 1.2.3.4" >> /etc/resolv.conf
        echo "nameserver 1.2.3.5" >> /etc/resolv.conf

        ;;

    stop)

        # restore resolv.conf
        mv /tmp/resolv.conf.orig /etc/resolv.conf

        # remove routing
        route del -net 1.2.0.0/16 dev tun0

        # kill the tunnel
        /etc/init.d/vpnc stop
        rmmod tun

        ;;

     *)
        echo "Usage: $0 (start|stop)" >&2
        exit 1

        ;;

esac

_________________
Saving the world, one kilobyte at a time.
Back to top
View user's profile Send private message
dncohen
n00b
n00b


Joined: 29 Nov 2004
Posts: 43

PostPosted: Thu Dec 06, 2007 12:44 am    Post subject: Reply with quote

I'm hoping to do the same thing. I've copied your example, and I've tried what I found in http://www.gentoo.org/doc/en/vpnc-howto.xml. I haven't quite figured out how to make my computer reach the outside world and the VPN at the same time.

Here are some of my settings before running vpnc:
Code:

george ~ # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
george ~ # more /etc/resolv.conf
# Generated by dhcpcd for interface eth0
search hsd1.ca.comcast.net.
nameserver 68.87.76.178
nameserver 68.87.78.130


Then after starting vpnc:
Code:

george ~ # /etc/init.d/vpnc start
 * Starting VPNC: vpnc ...                                                                                          [ ok ]
george ~ # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
65.98.33.10     192.168.1.1     255.255.255.255 UGH   0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 tun0
george ~ # more /etc/resolv.conf
#@VPNC_GENERATED@ -- this file is generated by vpnc
# and will be overwritten by vpnc
# as long as the above mark is intact
# Generated by dhcpcd for interface eth0
search hsd1.ca.comcast.net. medem.local
nameserver 10.0.0.14
nameserver 10.0.0.15


Can anyone tell me just by looking at the output of route -n above what I have to do to? Thanks.
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Thu Dec 06, 2007 10:52 am    Post subject: Reply with quote

You should use resolvconf-gentoo to manage the resolv.conf file instead of doing it yourself in that script.

I think vpnc supports it anyway, so you may not need to do anything.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
tuber
Apprentice
Apprentice


Joined: 12 Nov 2004
Posts: 267

PostPosted: Thu Dec 06, 2007 3:14 pm    Post subject: Reply with quote

For the route issue, I just modify /etc/vpnc/vpnc-script At the top of the file, after the comments, I added:
Code:
CISCO_SPLIT_INC=1
CISCO_SPLIT_INC_0_ADDR=10.0.0.0
CISCO_SPLIT_INC_0_MASK=255.0.0.0
CISCO_SPLIT_INC_0_MASKLEN=8
Now, vpnc will leave the default gateway alone, add a static network route to my company using the information above, and add one static host route per company DNS server.
Back to top
View user's profile Send private message
dncohen
n00b
n00b


Joined: 29 Nov 2004
Posts: 43

PostPosted: Fri Dec 07, 2007 4:04 pm    Post subject: Reply with quote

tuber, that appears to be most of what I needed.

I'm still having trouble with DNS, which brings me to UberLord's comment. I am not doing anything to resolve.conf. vpnc is doing that. In my post I'm just showing what happens to it.

After making the modification tuber suggested, my routes are improved, but vpnc still overwrites my resolve.conf. So I get a lot of unknown host errors. That is, while vpnc is running I can no longer ping www.yahoo.com, but I could ping 209.131.36.158.

Any ideas about that one? Thanks again.
Back to top
View user's profile Send private message
dncohen
n00b
n00b


Joined: 29 Nov 2004
Posts: 43

PostPosted: Fri Dec 07, 2007 4:11 pm    Post subject: Reply with quote

I figured out that resolvconf-gentoo is something I need to emerge. I did not have it.

So I've emerged it and configured it. Now things are working pretty well. I can connect to my vpn and the outside world simultaneously, which is great!

I'm noticing some delays with connections to the outside world, though. Is that normal?
Back to top
View user's profile Send private message
V-Li
Retired Dev
Retired Dev


Joined: 03 Jan 2006
Posts: 613

PostPosted: Thu Feb 28, 2008 1:00 pm    Post subject: Reply with quote

Just for your information: vpnc has support for hook scripts now, described in the official howto.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum