LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2018, 05:30 AM   #1
anon059
LQ Newbie
 
Registered: May 2018
Posts: 14

Rep: Reputation: Disabled
Firewall optimization


Hi all,

I've been toying around with my ubuntu machine turning it into a router (so I can achieve full vpn speeds) and came up with this firewall script which runs at start up.

Can anyone give me any tips on anything I may have missed. How it's looking etc.

Cheers in advance

Code:
#!/bin/sh

#Reset firewall
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F
/sbin/iptables -F
/sbin/iptables -X

#Reset IP6
/sbin/ip6tables -t nat -F
/sbin/ip6tables -t mangle -F
/sbin/ip6tables -F
/sbin/ip6tables -X

# Default policy to drop all incoming packets
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/ip6tables -P INPUT DROP
/sbin/ip6tables -P FORWARD DROP
/sbin/ip6tables -P OUTPUT DROP

# Accept incoming/outgoing packets from localhost
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

#Allow Plex
/sbin/iptables -A INPUT -p tcp --dport 32400 -j ACCEPT

#Accept local traffic
/sbin/iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT
/sbin/iptables -A OUTPUT -d 192.168.1.0/24 -j ACCEPT

#Accept VPN Server traffic
/sbin/iptables -A INPUT -s 192.168.181.0/24 -j ACCEPT
/sbin/iptables -A OUTPUT -d 192.168.181.0/24 -j ACCEPT

# Accept INPUT if initiated the connection
/sbin/iptables -A INPUT -m conntrack \
    --ctstate ESTABLISHED,RELATED -j ACCEPT

# Forward LAN packets to the WAN
/sbin/iptables -A FORWARD -o tun0 -j ACCEPT

# Forward WAN packets to the LAN if the LAN initiated the
# connection
/sbin/iptables -A FORWARD -i tun0 -m conntrack \
    --ctstate ESTABLISHED,RELATED -j ACCEPT

# NAT traffic going out the WAN interface
/sbin/iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE


#Start VPN
cd /firewall/
/usr/sbin/openvpn con.ovpn
 
Old 05-24-2018, 05:55 AM   #2
jonsnow987
LQ Newbie
 
Registered: May 2018
Posts: 1

Rep: Reputation: 0
good post.
 
Old 05-24-2018, 07:31 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
How to conduct firewall testing
 
1 members found this post helpful.
Old 05-29-2018, 04:56 PM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
^great link!
 
Old 05-29-2018, 07:18 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
^Only the best^
 
Old 06-01-2018, 07:00 PM   #6
anon059
LQ Newbie
 
Registered: May 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
I was after security rather than performance
 
Old 06-04-2018, 06:46 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
then you may wish to investigate "pfSense as a router".

Good Luck.
 
  


Reply

Tags
firewall, iptables, router, vpn



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rc.firewall optimization and determining why connections get cut dimm0k Linux - Security 11 10-26-2016 12:38 PM
Applying optimization recursively by compiling again using optimization flags $u$hil_k$ Linux - General 1 11-18-2013 12:19 PM
Best optimization univofky Linux - Distributions 2 02-15-2012 03:52 PM
firewall optimization canyon289 Linux - Software 1 10-22-2004 02:26 AM
firewall optimization canyon289 Linux - Games 0 10-21-2004 08:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration