Networking-Blog

My WordPress Blog

Linux: OpenSwan VPN

Below is an example OpenSwan configuration file with a brief explanation of each line.

conn <connname>

type=tunnel
the type of the connection; currently the accepted values are tunnel (the default) signifying a host-to-host, host-to-subnet, or subnet-to-subnet tunnel; transport, signifying host-to-host transport mode; passthrough, signifying that no IPsec processing should be done at all; drop, signifying that packets should be discarded; and reject, signifying that packets should be discarded and a diagnostic ICMP returned.

authby=secret
How the two security gateways should authenticate each other; acceptable values are “secret” for shared secrets, “rsasig” for RSA digital signatures (the default), secret|rsasig for either, and never if negotiation is never to be attempted or accepted (useful for shunt-only conns). Digital signatures are superior in every way to shared secrets.

auth=esp
Whether authentication should be done as part of ESP encryption, or separately using the AH protocol; acceptable values are esp (the default) and ah.

esp=3des-md5-96
(encrypted Secure Payload) defines what cipher, hash and PFSGroup you wish to use for the connection.

  # ONLY allow AES 256bit w/MD5
  esp=!aes256-md5
  # Prefer aes, 3des, blowfish in that order, but permit other combinations
  esp=aes,3des,blowfish
  # Only permit AES or 3DES with MD5 or SHA1
  esp=!aes-md5,!aes-sha1,!3des-md5,!3des-sha1

left=80.74.16.163
(required) the IP address of the left participant’s pub-lic-network interface, in any form accepted byipsec_ttoaddr(3) or one of several magic values.

leftsubnet=192.168.0.0/16

private subnet behind the left participant, expressed as network/netmask (actually, any form acceptable to ipsec_ttosubnet(3)); if omitted, essentially assumed to be left/32, signifying that the left end of the connection goes to the left participant only

right=85.234.71.226

(required) the IP address of the right participant’s pub-lic-network interface.

rightsubnet=192.168.1.0/24

private subnet behind the right participant, expressed as network/netmask.

keyingtries=3

how many attempts (a whole number or %forever) should be made to negotiate a connection, or a replacement for one, before giving up (default %forever). The value %forever means “never give up” (obsolete: this can be written 0). Relevant only locally, other end need not agree on it.

pfs=no
Whether Perfect Forward Secrecy of keys is desired on the connection’s keying channel (with PFS, penetration of the key-exchange protocol does not compromise keys negotiated earlier); acceptable values are yes (the default) and no.

rekey=yes

whether a connection should be renegotiated when it is about to expire; acceptable values are yes (the default) and no. The two ends need not agree, but while a value of no prevents Pluto from requesting renegotiation, it does not prevent responding to renegotiation requested from the other end, so no will be largely ineffective unless both ends agree on it.

auto=start
auto starts the vpn tunnel on a ipsec service restart.

keyexchange=ike

method of key exchange; the default and currently the only accepted value is ike

ikelifetime=1h

How long the connection to the other key-management daemon should last before being renegotiated; acceptable values as for keylife (default set by ipsec_pluto(8), currently 1h, maximum 8h).

keylife=8h

how long a particular instance of a connection (a set of encryption/authentication keys for user packets) should last, from successful negotiation to expiry; acceptable values are an integer optionally followed by s (a time in seconds) or a decimal number followed by m, h, or d (a time in minutes, hours, or days respectively) (default 8.0h, maximum 24h). Normally, the connection is renegotiated (via the keying channel) before it expires. The two ends need not exactly agree on keylife, although if they do not, there will be some clutter of superseded connections on the end which thinks the lifetime is longer.

dpdaction=restart

When a DPD enabled peer is declared dead, what action should be taken. hold (default) means the eroute will be put into %hold status, while clear means the eroute and SA with both be cleared. dpdaction=clear is really only usefull on the server of a Road Warrior config.

dpddelay=30

Set the delay (in seconds) between Dead Peer Dectection (RFC 3706) keepalives (R_U_THERE, R_U_THERE_ACK) that are sent for this connection (default 30 seconds). If dpdtimeout is set, but not dpddelay, dpddelay will be set to the default.

dpdtimeout=120
Set the length of time (in seconds) we will idle without hearing either an R_U_THERE poll from our peer, or an R_U_THERE_ACK reply. After this period has elapsed with no response and no traffic, we will declare the peer dead, and remove the SA (default 120 seconds). If dpddelay is set, but not dpdtimeout, dpdtimeout will be set to the default.

Cisco Linux IPSEC VPN

Create hq additional vpn profile on the vm :

conn comms1
left=90.90.90.90
leftsubnet=192.168.0.0/16
rightid=@commshq.networks.ww
right=217.33.177.219
rightsubnet=172.16.30.0/24
authby=secret
ikelifetime=1h
keylife=24h
keyingtries=3
rekey=yes
auto=start
esp=3des-md5-96
pfs=yes

Create comms2 additional vpn profile on the vm :

conn comms2
left=90.90.90.90
leftsubnet=172.16.30.0/24
right=216.12.12.12
rightsubnet=192.168.49.0/24
type=tunnel
authby=secret
auth=esp
esp=3des-md5-96
ikelifetime=1h
keylife=24h
keyingtries=3
pfs=yes
rekey=yes
auto=start
dpdaction=restart
dpddelay=15
dpdtimeout=30

Added additional vpn on hq router :

ip access-list extended VPN
remark LAN_TO_LAN
permit ip 172.16.30.0 0.0.0.255 192.168.0.0 0.0.255.255

Added additional vpn on comms2 router :

ip access-list extended VPN
remark LAN_TO_LAN
permit ip 192.168.49.0 0.0.0.255 172.16.30.0 0.0.0.255

Added additional rule to VM on the FORWARD chain to allow traffic
from 192.168.0.0 to 172.16.30.0 :

sudo iptables -I FORWARD 7 -s 192.168.0.0/255.255.0.0 -d 172.16.30.0/255.255.255.0 -j ACCEPT
!
Added additional rule to VM on the FORWARD chain to allow traffic
from
172.16.30.0 to
192.168.0.0 :

sudo iptables -I FORWARD 7 -s 172.16.30.0/255.255.255.0 -d 192.168.0.0/255.255.0.0 -j ACCEPT

Linux Securegate

/home/monitor/site name

[submenu] (COMMS)
[submenu] (Server)
[exec] (COMMS – Management Server) {xterm -fg white -bg black -fn 8×13 -T COMMS_Management -e /usr/bin/ssh -p 20345 FIREWALL@1.1.1.1}
[end]
[submenu] (Routers)
[submenu] (sites 1-10)
[exec] (COMMS124 – London) {xterm -fg white -bg black -fn 8×13 -T COMMS124 -e /usr/bin/telnet 1.1.1.1}
[exec] (COMMS462 – Home user – Ash Salman) {xterm -fg white -bg black -fn 8×13 -T COMMS462 -e /usr/bin/telnet 2.2.2.2}
[submenu] (FireBrick)
[sep]
[nop] (COMMS464 Leicester)
[exec] (DC Firebrick) {firefox http://10.10.10.10}
[exec] (Router1) {firefox http://10.10.10.11}
[exec] (Router2) {firefox http://10.10.10.11}
[exec] (Firebrick via R1) {firefox http://10.10.10.11:81}
[exec] (Firebrick via R2) {firefox http://810.10.10.11:81}
[exec] (COMMS464 – Leicester) {xterm -fg white -bg black -fn 8×13 -T WIT1464 -e /usr/bin/telnet 10.10.10.12}

Linux Iptables POSTROUTING

sudo iptables -vnL -t nat
sudo iptables -vnL -t nat –line-numbers
!
sudo iptables -t nat -D POSTROUTING 2
sudo iptables -A POSTROUTING 2 -t nat -s 192.168.1.0/255.255.255.0 -d 80.74.22.151 -j hml
sudo iptables -I POSTROUTING 11 -t nat -s 195.110.181.74 -d 172.20.0.0/16 -j ACCEPT
!
sudo iptables -I POSTROUTING -s 1.1.1.1 -d 2.2.2.2 -j ACCEPT
sudo iptables -I POSTROUTING -s 120.1.1.1/255.255.255.224 -o eth2 -j SNAT –to-source 1.1.1.1
!
!

When we have a linux vm solution in place :

Postrouting on VM through to Cisco Device…

sudo iptables -I POSTROUTING  -s 80.74.22.64/255.255.255.224 -d 109.231.196.34 -j ACCEPT

Cisco Router: on WAN IP = 80.74.22.64/32

ip nat inside source static tcp 172.16.24.1 5631 interface dialer 0 5631
ip nat inside source static udp 172.16.24.1 5632 interface dialer 0 5632
!
ip access-list extended 111
permit udp host 109.231.196.34 any eq 5632
permit tcp host 109.231.196.34 any eq 5631

Linux IP Forwarding

IP forwarding

#
# File: /etc/sysctl.conf
#
#—————————————————————
# Enable routing (IP forwarding)
#—————————————————————

net/ipv4/ip_forward = 1

Now use the sysctl -p command to activate the settings.

[root@bigboy tmp]# sysctl -p
…
…
net.ipv4.ip_forward = 1
[root@bigboy tmp]#

Linux Ipsec VPN Parameters

Parameters of the /etc/ipsec.conf file

Left – Internet IP address of the left-hand side VPN device.
Leftsubnet – The network protected by the left-hand side VPN device.
Leftid – Fully qualified domain name in DNS of the left-hand side VPN device, which is preceded by an “@” sign. If DNS is set up for the IP addresses, remove this entry, because names that don’t resolve correctly cause the VPN initialization to fail.
Leftrsasigkey – The entire left RSA sig public key for the left-hand side VPN device. This can be obtained by using the ipsec showhostkey –left command.
Leftnexthop – The next hop router from the left-hand side VPN device when trying to reach the right-hand side VPN device. You may use an auto-generated variable %defaultroute, which will be valid in most cases, or the actual IP address of the next hop router in cases where the next hop is not the default router.
Right – Internet IP address of the right-hand side VPN device.
Rightsubnet – The network protected by the right-hand side VPN device.
Rightid – Fully qualified domain name in DNS of the right-hand side VPN device, which is preceded by an @ sign. If DNS isn’t set up for the IP addresses, remove this entry, because names that don’t resolve correctly cause the VPN initialization to fail.
Rightrsasigkey – The entire right RSA sig public key for the right-hand side VPN device. This can be obtained by using the ipsec showhostkey –right command.
Rightnexthop – The next hop router from the right-hand side VPN device when trying to reach the right-hand side VPN device. You may use an auto-generated variable %defaultroute, which will be valid in most cases, or the actual IP address of the next hop router in cases where the next hop is not the default router.

e.g :

conn test
type=tunnel
authby=secret
auth=esp
esp=3des-md5-96
left=80.74.16.239
leftnexthop=85.234.66.212
leftsubnet=10.20.0.0/16
right=85.234.66.212
rightnexthop=80.74.16.239
rightsubnet=10.20.194.64/26
keyingtries=3
pfs=no
rekey=yes
auto=start
keyexchange=ike
ikelifetime=8h
keylife=24h
dpdaction=restart
dpddelay=15
dpdtimeout=30

Linux Route Add

ip route add 85.234.78.192/27 via 80.74.16.60 dev eth0
ip route add 80.74.17.9 via 80.74.16.60 dev eth0
ip route add 10.10.1.0/24 via 192.168.250.2 dev eth2
ip route add 10.10.9.0/24 via 192.168.250.2 dev eth2
!
sudo route add 10.10.9.0/24 gw 192.168.250.2 dev eth2
sudo /etc/init.d/iptables save
!

Show ip route table:

ip route

Edit File :

cd /etc/rc.d/

Use the following command to check the present routes.

netstat -r
netstat -rn
sudo ip route show
sudo ip route -n
sudo ip route show table local

sudo ip route show cache
sudo ip -s route show cache
sudo ip -s route get 172.20.4.0

Removing a specific route and emptying a routing table with ip route flush:

sudo ip route flush
sudo ip route flush 172.20.4.0/24

Adding routes to the startup:-

All these added routes will be lost whenever we restart the pc, in order to make these route entries permanent ot to make sure that these comes back automatically whenever a pc is restarted, issue the following commands.

Vi  /etc/rc.local

And insert the following command, save the file and exit.

route add -net 192.56.76.0 netmask 255.255.255.0 dev eth1
Route add –net 192.168.1.0/24 gw 192.168.1.1
Route add –host 192.168.1.1/32 gw 192.156.1.1

Rc.local is run every time your pc is restarted.

On Linux Gentu, you will find the routing tables under path : /etc/conf.d
edit file local.start

sudo vi /etc/conf.d/local.start

Linux MTU

sudo ip link set eth0 mtu 1500
!
sudo ifconfig
!

Enable MTU Path Discovery:

sudo vi /etc/sysctl.conf
!
# Path Maximum Transfer Unit discovery–disable this and the MTU settings are derived
# from the MTUs of all the hops along the# path to the host you are connecting to,
# including the host itself; 1 enables, 0 disables
net.ipv4.ip_no_pmtu_disc = 1

Allow MTU Path Discovery through the firewall :

sudo iptables -I FORWARD 7 -i eth0 -p tcp –tcp-flags SYN,RST SYN -j TCPMSS –clamp-mss-to-pmtu
sudo iptables -I OUTPUT 7 -i eth0 -p tcp –tcp-flags SYN,RST SYN -j TCPMSS –clamp-mss-to-pmtu