found on internet. Always difficult to start, especially for a newbie like me.
Great guide, thanks!
Annachronism: The Adventures of Anna Hegedus
| Build a Linux bridge firewall |
| Tutorials | ||||||||||||||||
| Written by Anna Hegedus | ||||||||||||||||
| Friday, 10 April 2009 16:50 | ||||||||||||||||
|
This tutorial will show you how to build a nice little firewall out of a Shuttle KPC. If you haven't built your KPC yet and want to know how, the other tutorial to do that is over here. I picked the KPC because it's ridiculously cheap. You can find the K45 for sale in some stores for as low as $99 by itself or for about $200 in a bundle that includes everything up to a hard drive. It's an awesome little versatile machine, and it's tiny, so you can fit them anywhere. This is a pretty low-power application so you don't really need a processor beyond a Celeron and maybe 2 gigs of RAM. If you were putting this in front of a whole network or a machine that drank traffic though, you should probably go with a machine that's a little more powerful. But if you're looking for something that'll protect a small network or a home, this is the ideal solution. Assuming your KPC is in front of you, assemble it, and let's get started! :)
They're gonna build a fire...they're gonna build a fire(wall). The first thing you want to do is install Debian on your KPC. I like Debian because it's simple, modular, and relatively easy to work with. If you want to download it, the images are at http://www.debian.org
The only real difference that you're going to see between this one and the other one that I built is that this one is going to have a beefier network card for ingress traffic. It's an Intel Pro 1000 GT. You can get them for about $50, and while it's not the greatest thing since Atari, you could do worse.
Install Debian as you normally would. Give your machine a decent hostname for a firewall, like, I don't know...
Getting started with the software install.
sudo apt-get install openssh-server
Once you press the Y key and enter, the openssh server will be installed along with a bunch of other necessary packages. Make sure your passwords are secure for your users. You may want to disable root login for SSH. To do that:
nano /etc/ssh/sshd_config
Install the packages.
Issue this command to install the two network filters. Iptables, the IP-based filter, and ebtables, the MAC address filter. apt-get install ebtables iptables Once those two packages are installed, you will want to get the software that makes bridging possible. Because we have two network cards in our machine, we need to tell Debian that it's all right to allow traffic to pass from one port to another. We will use the bridge-utils package to do this. apt-get install bridge-utils There's one major command you'll need to get used to with bridge-utils, and that's brctl. The brctl command essentially sets the bridge, allows you to monitor it, add interfaces, remove interfaces...you name it. Debian doesn't really know how to use the bridge yet. To do that, you need to go into a file where Debian stores the network config and tailor the file to your needs/wants/desires. The file is /etc/network/interfaces. nano /etc/network/interfaces Use the following file as a template. # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5).
auto lo iface lo inet loopback
iface eth0 inet manual iface eth1 inet manual
pre-up iptables-restore < /etc/iptables.up.rules bridge_ports eth1 eth0 auto br0
# The loopback network interface auto lo iface lo inet loopback
Well, these lines are for the local interface, or loopback. The interface doesn't really exist physically, but exists virtually so that your machine can talk to itself. The "auto" line tells the interface that it's all right to come up by itself, while the iface line sets the basic parameters for the local interface. Mainly, that this is a loopback.
iface eth0 inet manual iface eth1 inet manual This sets the network interfaces to manual so they don't attempt to come up by themselves and attempt to contact SkyNet.
iface br0 inet dhcp pre-up iptables-restore < /etc/iptables.up.rules bridge_ports eth1 eth0 auto br0 The real meat of the file. This tells the machine that interface br0 (the bridge) will grab its address from DHCP and that interface br0 is composed of bridged ports ethernet 0 and ethernet 1. Before the interface is brought up, the command "iptables-restore" will be ran, restoring the iptables configuration file that exists at /etc/iptables.up.rules. We'll create that file now. It'll be important when you create your firewall rules. That's where they go! echo "" > /etc/iptables.up.rules
Let's play Bridge -- I hate solitaire (I know, I'm sorry).
Once it does, look at the interface configuration and you'll see some jolly-good fun: ifconfig | more br0 Link encap:Ethernet HWaddr ****** inet addr:**** Bcast:***** Mask:***** inet6 addr:****** Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:227 errors:0 dropped:0 overruns:0 frame:0 TX packets:71 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:22906 (22.3 KiB) TX bytes:9759 (9.5 KiB)
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:17
inet6 addr: ********* Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:290 errors:0 dropped:0 overruns:0 frame:0 TX packets:77 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:32424 (31.6 KiB) TX bytes:10227 (9.9 KiB)
inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:560 (560.0 B) TX bytes:560 (560.0 B) So there you see several interfaces and a new one named Br0 that stole your IP address. That's okay -- that's what we wanted to happen. You see, that new interface is actually the bridge interface that we wanted...the combined eth0 and eth1. It's kind of the Voltron of both network cards. Now for some fun. Test to see if you've got network connectivity on the other side of the bridge by plugging your equipment into the other interface on the backside of the box. By default, all traffic will flow through the box with no firewall rules in place, so anything should go. The fun thing is that the box is completely transparent to the other side, so your IP address will still be whatever your DHCP box assigned. For something even more interesting, try out the command "brctl show br0":
iptables: Let's do this.
By default, iptables comes with several different "chains" that you can work with...mostly, an INPUT chain, an OUTPUT chain, and a FORWARD chain. There are many different things that you can do with iptables, but for the purposes of this, we are going to keep things simple. First of all, keep in mind that you have two interfaces. most of your commands will look something like this: iptables -A FORWARD -s 191.2.0.0/16 -i br0 -p tcp -m tcp --dport 123 -j ACCEPT That command will put a rule in the ruleset for the chain FORWARD that allows any machine on the network 191.2.x.x to send traffic on TCP port 123. At the very end of the FORWARD chain, there's a rule that looks like this: iptables -A FORWARD -i br0 -m state --state RELATED,ESTABLISHED -j ACCEPT This rule will allow traffic that is a response of sent traffic to keep coming through the bridge. The "related" statement allows certain traffic from FTP and ICMP messages through. -A FORWARD -i br0 -j DROP This rule drops any and all other traffic that isn't explicitly allowed. To list out the rules that you have so far, try the following: iptables --list So lets do this Pittsburgh-style: Roughshod and with a Primanti's sandwich in one hand. iptables -A FORWARD -s 1.2.244.0/23 -i br0 -p udp -m udp --dport 137:139 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
So when you're done building your ruleset, don't forget to save it to the file that we specified above in the /etc/network/interfaces config. iptables-save > /etc/iptables.up.rules When you go to reboot, now it'll remember your rules. And that's about that!
UPDATE - 5/18/2009If you use something like multicast DNS or broadcasts, you may need to explicitly allow those in your firewall settings. I had to use the following firewall rules on my personal box to allow mDNS and broadcast traffic across the wire: iptables -A FORWARD -i br0 -o br0 -s 1.2.244.0/23 -m pkttype --pkt-type multicast -j ACCEPT
Comments (2)
Powered by !JoomlaComment 4.0 beta2
|
||||||||||||||||
| Last Updated on Monday, 18 May 2009 17:46 |
Hi! Its your hairdresser in need of y...
Hi Dale, If you take it apart and cl...
hey my buttons arent coming back up l...
Hi Simon, The keychain version can...
how much does tv b gone cost,and wher...