Professional Documents
Culture Documents
You should have basic knowledge of how routing works, what routes are and how to install/configure programms in ubuntu/debian. Also, some understanding about iptables helps
PART 1
prerequisite
Both routers rA and rB have ip forwarding enabled. If they NAT or not does not matter. Both Network go THROUGH the router to the internet. (it can be done without this, but requires more setup which is beyond the scope of this howto)
server on. Create the file (and open an editor) with this command (i always name the files after what they are connected to. Since this is a static link to one host, i will name it after the host that the connection it to go to): Code:
dev tun0 remote rB.example.net ifconfig 10.0.0.1 10.0.1.1 secret /etc/openvpn/static.key daemon lport 15000 rport 1194 user nobody group nogroup persist-key persist-tun status /var/log/openvpn/rB.example.net-status.log log-append /var/log/openvpn/rB.example.net.log ping-restart 60 ping 20
The bold bits need to be changed to your acctual setting, the rest can stay the same for now. anything below the daemon can be ommited (for now) as it is tweaks, security enhanchement and setting we will need later on, but i would suggest you leave it in anyway. This config in short does not following (line by line): * it will create a new network device tun0 * it will connect to the host rB.example.net * tun0 will have the IP address of 10.0.0.1 - the remote partner is expected to have the IP addres 10.0.1.1 * there is a static key to be used, found in /etc/openvpn/static.key * openvpn shall run as a daemon - i.e. go into the background after the connection is established * locally, openvpn will bind to port 15000 * the remote server is bound to port 1194 * openvpn shall drop its privilegdes to the user nobody * openvpn shall drop its group to nogroup * keep the static key in the memory, even upon reconnect * keep the tun device open, even upon reconnect * log status of the connetion to the given file * log messages to the given file * assume the connection to be dead if no ping was recheived for 60 seconds (trigger reconnect) * try to ping the remote host every 20 seconds This was almost it for the openvpn, just a few minor things remain. First, the directory for the log files does not yet exist. create it and then change it's owner to nobody and group nogroup so the openvpn process can write to it Code:
4.) configuring rB
This is going to be almost exactly the same as rA for the config file. There are just three changes to the file. 1.) the remote statement has to be changed to hold the fqdn of rA instead of rB 2.) the ifconfig statement needs to be reversed, as the local IP of rA is the remote IP of rB and vice versa 3.) the ports in rport and lport need to be swapped for the same reason the ifconfig has to be swapped. open file for editing on rB
Code:
dev tun0 remote rA.example.net ifconfig 10.0.1.1 10.0.0.1 secret /etc/openvpn/static.key daemon lport 1194 rport 15000 user nobody group nogroup persist-key persist-tun status /var/log/openvpn/rA.example.net-status.log log-append /var/log/openvpn/rA.example.net.log ping-restart 60 ping 20
remember to change the bold bit to the real name, the rest can be copied if you want to keep as close to the tutorial as possible now, create the logging directory again and all is set for a first testrun. Code:
sudo su iptables -A INPUT -p udp --sport 1194 --dport 15000 -j ACCEPT iptables -A OUTPUT -p udp --sport 15000 --dport 1194 -j ACCEPT
sudo su iptables -A INPUT -p udp --sport 15000 --dport 1194 -j ACCEPT iptables -A OUTPUT -p udp --sport 1194 --dport 15000 -j ACCEPT
With these, you are able to connect the openvpn processes. However, it does not yet allow any connections to utilize this link from the attached networks. NOTE: i have chosen the stateless approach as they are easier to understand. Even though the kernel can handle the Openvpn Connection statefull (despite the fact that we utilize udp at the moment) i thought it to be less confusing.
Thu Apr 10 11:27:35 2008 OpenVPN 2.0.9 i486-pc-linux-gnu [SSL] [LZO] [EPOLL] bui lt on Sep 20 2007 Thu Apr 10 11:27:35 2008 TUN/TAP device tun0 opened Thu Apr 10 11:27:35 2008 ifconfig tun0 10.0.0.1 pointopoint 10.0.1.1 mtu 1500 Thu Apr 10 11:27:35 2008 GID set to nogroup Thu Apr 10 11:27:35 2008 UID set to nobody Thu Apr 10 11:27:35 2008 UDPv4 link local (bound): [undef]:15000 Thu Apr 10 11:27:35 2008 UDPv4 link remote: x.x.x.x:1194 Thu Apr 10 11:27:45 2008 Peer Connection Initiated with x.x.x.x:1194 Thu Apr 10 11:27:46 2008 Initialization Sequence Completed
using ifconfig, there should be a device called tun0 now which would look like this Quote:
someone@server:# ifconfig tun0 tun0 Protokoll:UNSPEC Hardware Adresse 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet Adresse:10.0.0.1 P-z-P:10.0.1.1 Maske:255.255.255.255 UP PUNKTZUPUNKT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:167 errors:0 dropped:0 overruns:0 frame:0 TX packets:175 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlnge:100 RX bytes:14740 (14.3 KiB) TX bytes:10705 (10.4 KiB)
also, from rA you should now be able to ping rB by it's internal ip address - 10.0.1.1. from rB. the same going the other direction. it is essential that this connection is up and running. Anything that follows now will need to reachability over this connection now. So make sure you can ping with the internal IP addresses
generated upon creating the device. on rA, add this line to the rB.example.net Quote:
sudo su iptables -A FORWARD -i tun0 -o eth0 -j ACCEPT iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT
you should now be able to ping and access any host on nB from nA and vice versa. The Bridge us up and running, the networks have been joined via a virtual direct link between the routers.
Part 2
Most of what has been done in Part One is unsuable in the setting we are after now. We will join the two Networks, nA and nB together to use a single IP Range. Clients on either network will not be able to distinguish anymore if the remote computer is on their physical Network or on the other side of the VPN. Naturally, only one default gateway can be set in this scenario, resulting in ALL traffic going over the VPN from one to the network. Only apply these settings if there is no other way and you understand what it means to join two networks on MAC layer!
Also i must warn you - again - that this setup is only to be used with caution as it can produce a lot of unneccessary traffic between the networks. If you have already done Part 1, you can ommit step two, but must turn off the bridge setup done in part 1. it will be in the way and confuse the routing. Only Step 2 can be taken from Part 1. All other steps have changed or they do something completly different now... so, i will start at point 1, skip point 2 and work my my way from three onwards.
auto eth1 iface eth1 inet static address 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 network 192.168.1.0
now, change where you see the eth1 into a br0. This will case a bridge to come up at boot time with the configruation of your previous configuration of eth1. After that is done, you also need to tell the bridge that it should contain the device eth1 - this can be done with the line Quote:
bridge_ports eth1
so, when you are done with changeing the entries, your full entry for br0 should look like this Quote:
auto br0 iface br0 inet static address 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 network 192.168.1.0 bridge_ports eth1
make sure you have chosen the right interface. If your internal network is not bount to eth1, change any apperance of eth1 into the appropriate device The last thing to do is to also configure eth1 upon boot to not have any ip, but to use promisc mode and to come up so we can see/hear anything that comes in on that device. So, right after configuration of br0 we will define a new block for eth1, looking like this: Quote:
auto eth1 iface eth1 inet manual up ifconfig $IFACE 0.0.0.0 up up ip link set $IFACE promisc on down ip link set $IFACE promisc off down ifconfig $IFACE down
the network configuration should be done now. To really check if these settings worked you will need to reboot your machine. so, lets do exactly that. Once the reboot is done, first check your network devices with ifconfig - your output should now look like this
Code:
test:~# ifconfig br0 Protokoll:Ethernet Hardware Adresse 00:0C:29:77:B1:6A inet Adresse:192.168.1.1 Bcast:172.16.64.255 Maske:255.255.255.0 inet6 Adresse: fe80::20c:29ff:fe77:b16a/64 Gltigkeitsbereich:Verbindung UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:155 errors:0 dropped:0 overruns:0 frame:0 TX packets:128 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlnge:0 RX bytes:14239 (13.9 KiB) TX bytes:18581 (18.1 KiB) eth1 Protokoll:Ethernet Hardware Adresse 00:0C:29:77:B1:6A inet6 Adresse: fe80::20c:29ff:fe77:b16a/64 Gltigkeitsbereich:Verbindung UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:155 errors:0 dropped:0 overruns:0 frame:0 TX packets:134 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlnge:1000 RX bytes:16409 (16.0 KiB) TX bytes:19049 (18.6 KiB) Interrupt:177 Basisadresse:0x1400 Protokoll:Lokale Schleife inet Adresse:127.0.0.1 Maske:255.0.0.0 inet6 Adresse: ::1/128 Gltigkeitsbereich:Maschine UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlnge:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
lo
the bold bits mark the crucial settings. br0 now has your ip address, while eth1 is unconfigured (as no ip) and is in promisc mode. Both networkcards should be marked as up. The last thing to check is if eth1 really got added to br0. This can be checked via brctl show br0 - the output should look like the following: Code:
STP enabled no
interfaces eth0
if all the settings are correct, and you run into trouble with the network connectivity, check your iptables/firestarter configuration if it is still expecting pakets on eth1 and change those rules to br0 as this is now your internal network card.
#! /bin/sh BR=$1 DEV=$2 MTU=$3 /sbin/ifconfig $DEV mtu $MTU promisc up /usr/sbin/brctl addif $BR $DEV
next is the file which will remove the tap device from the bridge. i'll call it down.sh, and it should also be placed into the /etc/openvpn folder. Content of it reads as follows: Code:
#! /bin/sh BR=$1 DEV=$2 /usr/sbin/brctl delif $BR $DEV /sbin/ifconfig $DEV down
lastly, make both files exectuable with these commands (adding the +x bit) Code:
dev tap0 remote rB.example.net secret /etc/openvpn/static.key daemon up "/etc/openvpn/up.sh br0" down "/etc/openvpn/down.sh br0" lport 15000 rport 1194 user nobody group nogroup persist-key persist-tun status /var/log/openvpn/rB.example.net-status.log log-append /var/log/openvpn/rB.example.net.log ping-restart 60 ping 20
configuration for rB Quote:
up "/etc/openvpn/up.sh br0" down "/etc/openvpn/down.sh br0" lport 1194 rport 15000 user nobody group nogroup persist-key persist-tun status /var/log/openvpn/rA.example.net-status.log log-append /var/log/openvpn/rA.example.net.log ping-restart 60 ping 20
note that the main difference is the missing of the ifconfig statement. Since we now forward on layer 2, we don't need explicit ip addresses for the tap devices anymore. Otherwise, the config files are pretty much the same. Again, anything after the daemon can be ommited. Also, make sure to change the bold bits to th fqdn of the servers to connect to. Lastly, note the up and down commands supplied in the config. These entires will run the scripts we created in step 4 and make sure that the tap device is added to the bridge properly. if you chose a different name than br0 for your bridge, you will need to change these commands. Otherwise, leave them untouched.
test:~# brctl show br0 bridge name bridge id STP enabled interfaces br0 8000.000c2977b16a no eth0 tap0
If both bridges look like that your networks are now joined. If you place a host in nB with an address of nA , you can reach it from anywhere as if it were in nA. Another way of testing it would mean placing a computer with the IP 192.168.2.1 in nB , placing a computer with the IP 192.168.2.2 in nA and then try to ping each other. (the IP's can of course be freely chosen). I have chosen IP's that do not match either network (nA or nB) to show the power of the bridge. Even tho neither rA nor rB know about any 192.168.2.0/24 network, the two hosts which are in two seperate networks can ping each other over the bridge. If this works, your basic setup is complete and the bridge is working normally.
them, or block any dhcp-request/lease from passing the bridge. Otherwise you might run into some very strange results, possibly not know anymore where one network ends and the other starts. ONLY have one dhcp server per network - ever b) if you wish to block pakets in uptables, you must now use the br0 device. This means you will have rules for pakets that come in and go out on the br0 device. This may sound silly, but sooner or later you will run into this problem c) if you have joined the network together, and you chose to have one ip-range over both networks, be aware that this will put a lot of stress on the other router. So, if you chose that nB should now go into the ip-range of nA, it would mean that any paket to the internet from nB would first travel to rA and then go to the net from there. With fast internet connection this might be possible, but especially with adsl links this i NOT a desired behaviour.