View previous topic :: View next topic |
Author |
Message |
bastibasti Guru
Joined: 27 Nov 2006 Posts: 590
|
Posted: Sat Nov 03, 2007 10:23 am Post subject: VPNC & Default route |
|
|
Hi there,
thus I dont know much about routing, I have to ask the question
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 |
|
|
tarpman Veteran
Joined: 04 Nov 2004 Posts: 1083 Location: Victoria, BC, Canada
|
Posted: Sat Nov 03, 2007 6:44 pm Post subject: |
|
|
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 |
|
|
bastibasti Guru
Joined: 27 Nov 2006 Posts: 590
|
Posted: Sun Nov 04, 2007 9:24 am Post subject: |
|
|
That would be great! |
|
Back to top |
|
|
tylerwylie Guru
Joined: 19 Sep 2004 Posts: 458 Location: /US/Georgia/Atlanta
|
Posted: Sun Nov 04, 2007 9:45 am Post subject: |
|
|
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 |
|
|
bastibasti Guru
Joined: 27 Nov 2006 Posts: 590
|
Posted: Sun Nov 04, 2007 12:26 pm Post subject: |
|
|
I think the script deletes thze default route and restores it on disconnect. |
|
Back to top |
|
|
tarpman Veteran
Joined: 04 Nov 2004 Posts: 1083 Location: Victoria, BC, Canada
|
Posted: Mon Nov 05, 2007 3:44 am Post subject: |
|
|
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 |
|
|
dncohen n00b
Joined: 29 Nov 2004 Posts: 43
|
Posted: Thu Dec 06, 2007 12:44 am Post subject: |
|
|
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 |
|
|
UberLord Retired Dev
Joined: 18 Sep 2003 Posts: 6835 Location: Blighty
|
|
Back to top |
|
|
tuber Apprentice
Joined: 12 Nov 2004 Posts: 267
|
Posted: Thu Dec 06, 2007 3:14 pm Post subject: |
|
|
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 |
|
|
dncohen n00b
Joined: 29 Nov 2004 Posts: 43
|
Posted: Fri Dec 07, 2007 4:04 pm Post subject: |
|
|
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 |
|
|
dncohen n00b
Joined: 29 Nov 2004 Posts: 43
|
Posted: Fri Dec 07, 2007 4:11 pm Post subject: |
|
|
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 |
|
|
V-Li Retired Dev
Joined: 03 Jan 2006 Posts: 613
|
Posted: Thu Feb 28, 2008 1:00 pm Post subject: |
|
|
Just for your information: vpnc has support for hook scripts now, described in the official howto. |
|
Back to top |
|
|
|