A geek's geek-log My not-so-secret diary

Thursday Apr 30, 2009

Assume that you’re running a two interface firewall setup using Shorewall for your institute LAN. Suppose you have an internal webserver that you want to be made visible externally as well. To achieve this, you’d normally do a port forward using DNAT. Although this method gets a FAIL when it comes to security, it’s usually the easiest thing to do. The suggested alternative would obviously be to get an extra NIC and setup a DMZ but anyways I’ll be talking about a two interface setup here. Now this port forwarding thing works fine but what happens when a host in the internal network tries to access this website through the URL? The request will go out of the network, come back in and the response would follow the reverse route and this will take ridiculously long! There are two workarounds for this. The recommended method would be to configure your internal DNS to respond with the internal IP when a DNS query for the webserver’s URL is received. The other method would be to have your gateway masquerade as the internal webserver, which is nothing short of a quick hack and note that this is also rather poor when it comes to security. As per the shorewall website, for a transparent proxy, you’ll need to add the following rules.

Example IP addresses:

Gateway’s external interface (eth0): 210.45.21.55

Gateway’s internal interface (eth1) : 192.168.1.1

Internal Webserver: 192.168.1.10

So here come the rules:

In/etc/shorewall/rules:

REDIRECT        loc     3128    tcp     www     -       !210.45.21.55

DNAT              loc     loc:192.168.1.10      tcp     www     -       210.45.21.55

In/etc/shorewall/masq:

eth1:192.168.1.10        eth1           192.168.1.1      tcp     www

In /etc/shorewall/interfaces, make sure you have the ‘routeback’ option enabled for eth1.

Now here’s the part that you won’t find in the shoerwall documentation. In case you’re migrating to a non-transparent proxy, add the following rule after the above mentioned DNAT.

DNAT    $FW     loc:192.168.1.10:80      tcp     80      -       210.45.21.55

Monday Jan 26, 2009

Well, going by what actually happened at the National Internet Backbone’s nodal center in Jaipur, a more apt title would have been something like:

“Attempt at Setting up MRTG for BSNL, Jaipur, Swiftly Denied by a Network Problem”

Like I mentioned before, we had some serious network related issues when we were trying to configure the (really old) server they’d given us to setup MRTG on. We were to configure the network interface settings on the Red Hat server according to a hand book they’d given me. After setting the IP and the subnet mask, I went on to add the default gateway route. And heck, the gateway wasn’t visible from the LAN! I thought that perhaps, the hand book had older details and they’d probably reconfigured their routers in the server room we were in. But when Mr S.C Gupta, the head of the nodal office, told me that all other hosts in the same network are using the gateway that was specified in the manual (which was Rajasthan’s gateway to the internet backbone), I was taken aback. Not once in my system administration experience had I encountered a situation where a router was visible to all hosts but one within the same VLAN (assuming no one went through the trouble of setting a port block in the switch)! Furthermore, I was able to ping all these hosts from the server in question and vice versa, but the router still stood defiant (when I get my hands on it…grrr). My suspicion about the router having disabled incoming pings were also put to waste when I saw that it’s working with the other devices on the same LAN. Just to be sure, I checked and double checked the configuration of all other systems on the network, and they all seemed green. How queer. To make matters worse, no one really knew how these devices were networked. After tackling the problem for about 4 hours, me and my junior Nithin, decided to leave and come back some other time because the station was to go on a power maintenance shutdown. Man was I glad I left that place!