One of the most difficult problems when dealing with a firewall is that the network or subnetwork we want to protect usually has to be split into at least two subnetworks: one on the external side and one on the internal, protected side. This, apart from the planning stage, can result in the reconfiguration of all machines in the network to the new configuration. What is worse is that in case of a hardware fault of the firewall, you'll have to reconfigure all machines in your network so they will be able to see the outside until you repair the firewall machine. The configuration of the firewall can be even harder if you don't have access to the configuration of the machine that actually connects your network to the external world, very often a router or something leased from a telco (telephone company).
We are going to explain a smarter way of adding a firewall to your network without breaking it into subnetworks or reconfiguring any machine on the internal or external network, except from the firewall machine itself, by just fooling the other machines into thinking nothing changed. We will cover the aspects of the network configuration and packet routing, not real packet-filtering firewalling, since this has already been covered in depth in another Linux Journal issue (see Resources).
In the practical examples, we will pretend we have a C class network, where our contact with the external network is the .1 machine in the network (let it be a router, a machine or whatever). We will assume the IP numbers .2 and .3 to be free for our use. We will also need another IP greater than or equal to .4, so we must be sure these aren't used for other purposes. Of course, with a different network configuration, you'll have to adjust some calculations to make the method fit your needs. To make things even clearer in the examples below, let's fix our C class network to the 126.96.36.199 one.
As for the Linux box that will work as a firewall, you must actually have the kernel compiled with the usual networking options, including IP forwarding and IP firewalling and whatever you else may need, for example, IP accounting. Also, enable IP forwarding in the kernel; in newer kernels, this is done by enabling it directly in the /proc file-system. (For example, by using echo 1>/proc/sys/net/ipv4/ip_forward. Your initialization scripts should take care of this.) Another thing to note is that you should have a working arp program installed on your system. In fact, some distributions are shipped with an arp binary that is compiled without the new SIOCSARP kernel interface, so it doesn't work, and if you forget to check this one thing, it may cause you many unnecessary headaches.
The Linux box must have two Ethernet cards installed: eth0, connected to the internal network; and eth1, directly connected to the gateway machine for our network to the world.
Now, the network interfaces on the firewall machine must be configured. The internal network interface will be configured in the same way as the other internal machines, as if it had all machines on the network. So in our class C example, the eth0 configuration would be the following:
inet addr : 188.8.131.52 network : 184.108.40.206 broadcast : 220.127.116.11 netmask : 255.255.255.0
Remember that in place of 18.104.22.168, you can use any other unused address. The commands to do this are
ifconfig eth0 22.214.171.124 netmask 255.255.255.0\ broadcast 126.96.36.199 route add -net 188.8.131.52This configuration will also apply to all machines in the internal network behind the firewall; of course, the IP address will change on each.
The second network interface, eth1, will be configured as if it had a very small network; actually, four IPs is the least we can manage. This is where the firewall machine and the gateway will be placed.
inet addr : 184.108.40.206 network : 220.127.116.11 broadcast : 18.104.22.168 netmask : 255.255.255.252
This is obtained using the following commands:
ifconfig eth1 22.214.171.124 netmask 255.255.255.252\ broadcast 126.96.36.199 route add -net 188.8.131.52 route add default gw 184.108.40.206The routing table is now set, so that packets for the entire class C network will be redirected to the internal eth0 interface, while the packets for the small network will be routed to the external eth1 interface. Finally, the default gateway has to be set for all machines on the internal network, that is, 220.127.116.11. Please note that this routing scheme works because the most specific route is applied first.
There are two more questions to solve. First, how will the gateway know how to reach the internal machines? Remember, we haven't changed the gateway configuration, so it still thinks it has the C class network attached to it. Second, how will the machines be able to reach the gateway? After all, they still believe they have the entire C class network, including 18.104.22.168, on their network interface. Well, it will be easy; we just make believe all the machines are on a class C network. The trick is to hack the process of translating the IP address to the hardware (in our case, Ethernet) address, which is called the ARP (address resolution protocol). (If you're not familiar with this, please consult the NET-HOWTO and Proxy-ARP miniHOWTO.) This can easily be done by telling our firewall machine to answer all ARP requests for the gateway on the internal network and reply to all requests for any internal machines from the gateway. Practically, this is done in two stages. First, by publishing, via arp, the gateway and the firewall machine on the internal network, more exactly:
arp -v -i eth0 -Ds 22.214.171.124 eth0 pub arp -v -i eth0 -Ds 126.96.36.199 eth0 pub
Thus, when someone asks for .1 or .2 on the internal network, the firewall will reply, giving its Ethernet hardware address. In the second stage, we will publish all internal network IPs from .4 to .255, on the firewall-gateway small network. For the entire C class network, it look like this:
arp -v -i eth1 -Ds 188.8.131.52 eth1 netmask\ 255.255.255.128 pub arp -v -i eth1 -Ds 184.108.40.206 eth1 netmask\ 255.255.255.192 pub arp -v -i eth1 -Ds 220.127.116.11 eth1 netmask\ 255.255.255.224 pub arp -v -i eth1 -Ds 18.104.22.168 eth1 netmask\ 255.255.255.240 pub arp -v -i eth1 -Ds 22.214.171.124 eth1 netmask\ 255.255.255.248 pub arp -v -i eth1 -Ds 126.96.36.199 eth1 netmask\ 255.255.255.252 pubThis way, we have partitioned the address space and published all our IPs. When the gateway asks for the hardware address of an internal machine, the firewall will reply giving its address. Since we turned on the IP packet forwarding, once the firewall has a packet and replies to the ARP request, it will forward it to the destination machine according to the routing table.
This solution has proven to be very useful for us, especially when we had to enhance the existing network without causing “too much trouble”. The last step is, of course, tuning the firewall, IP accounting, transparent proxy or whatever you need on the Linux box—but that is another story.
Federico is studying computer science at the University of Udine. When not hacking or coding he enjoys reading sf, listening to music and playing guitar. He can be reached at email@example.com.
Christian Pellegrin is studying astrophysics at the University of Trieste and works part-time as a system administrator and teacher in a high school. When not playing with Linux and other fun software or hardware he enjoys discussing who is the best film director of all times with his girlfriend. E-mails are welcome at firstname.lastname@example.org.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Chris Birchall's Re-Engineering Legacy Software (Manning Publications)
- The Italian Army Switches to LibreOffice
- Linux Mint 18
- Petros Koutoupis' RapidDisk
- ServersCheck's Thermal Imaging Camera Sensor
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Privacy and the New Math
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide