Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The following is what I got after googling:

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT #allow loopback access
iptables -A OUTPUT -d 255.255.255.255 -j ACCEPT #make sure you can communicate with any DHCP server
iptables -A INPUT -s 255.255.255.255 -j ACCEPT #make sure you can communicate with any DHCP server
iptables -A INPUT -s 192.168.0.0/16 -d 192.168.0.0/16 -j ACCEPT #make sure that you can communicate within your own network
iptables -A OUTPUT -s 192.168.0.0/16 -d 192.168.0.0/16 -j ACCEPT
iptables -A FORWARD -i eth+ -o tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -o eth+ -j ACCEPT # make sure that eth+ and tun+ can communicate
iptables -t nat -A POSTROUTING -o tun+ -j MASQUERADE # in the POSTROUTING chain of the NAT table, map the tun+ interface outgoing packet IP address, cease examining rules and let the header be modified, so that we don't have to worry about ports or any other issue - please check this rule with care if you have already a NAT table in your chain

Here's what I did:

A. As I am using Debian, I installed iptables-persistent.

B. I sudo /etc/iptables/rules.v4 and replaced the default in it with the following:

*filter
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT #allow loopback access
-A OUTPUT -d 255.255.255.255 -j ACCEPT #make sure you can communicate with any DHCP server
-A INPUT -s 255.255.255.255 -j ACCEPT #make sure you can communicate with any DHCP server
-A INPUT -s 192.168.0.0/16 -d 192.168.0.0/16 -j ACCEPT #make sure that you can communicate within your own network
-A OUTPUT -s 192.168.0.0/16 -d 192.168.0.0/16 -j ACCEPT
-A FORWARD -i eth+ -o tun+ -j ACCEPT
-A FORWARD -i tun+ -o eth+ -j ACCEPT # make sure that eth+ and tun+ can communicate
-t nat -A POSTROUTING -o tun+ -j MASQUERADE # in the POSTROUTING chain of the NAT table, map the tun+ interface outgoing packet IP address, cease examining rules and let the header be modified, so that we don't have to worry about ports or any other issue - please check this rule with care if you have already a NAT table in your chain
-A OUTPUT -o eth+ ! -d 111.222.333.444 -j DROP # if destination for outgoing packet on eth+ is NOT a.b.c.d, drop the packet, so that nothing leaks if VPN disconnects
COMMIT

C. I save the changes to /etc/iptables/rules.v4 and reboot the computer. Note that 111.222.333.444 is an example of an IP address of the VPN server located in XYZ country

D. Upon reboot, I am unable to connect to the VPN server. Something is wrong with the contents of rules.v4

share|improve this question
6  
what are you trying to accomplish? –  Creek Apr 26 at 13:33
    
@Creek: I am hoping that someone will show me how to use the above iptables on Debian or Ubuntu. Specifically, do I need to convert the above set of iptables into a bash file and then execute it? And do I have to write additional scripts to bring up the iptables rules when the VPN is down? –  user66229 Apr 30 at 18:31
1  
You can put it in a file and import it into iptables using $ sudo iptables-restore < file As for your VPN question, there's not enough information here to really answer that. If you copied this ruleset from a tutorial, ask the author –  Creek May 1 at 1:11
    
@Creek: I added some details to my original post. Do you think you can help me out? –  user66229 May 1 at 14:18
    
@user66229 these rules are scary. You should really tell what you want to do and not just use that. –  Spack May 2 at 14:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.