Kevin Warrington

Loading clever subtitle...

Manipulating Unix Routing Tables

For one of our latest projects, we needed to restrict incoming connections on the destination server prior to launching the our website.

So, we had our developers route their traffic through a VPN gateway by adding entries to the routing table:

1
sudo route -nv add IP_DESTINATION IP_GATEWAY

You can verify the route was added by using netstat

1
2
3
4
5
6
netstat -rn
# Routing tables
#
# Internet:
# Destination        Gateway            Flags        Refs      Use   Netif Expire
# IP_DESTINATION     IP_GATEWAY         UGHS            0        0     en0

You can verify the connection is going through the vpn by using traceroute

1
2
3
traceroute IP_DESTINATION
# traceroute to IP_DESTINATION, 64 hops max, 52 byte packets
#  1  IP_GATEWAY  1.586 ms  2.257 ms  0.885 ms

You can remove the route by using the delete option

1
2
sudo route delete IP_DESTINATION
# delete host IP_DESTINATION

Comments