⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firewall.sh

📁 OpenVPN is a robust and highly flexible tunneling application that uses all of the encryption, authe
💻 SH
字号:
#!/bin/bash# A Sample OpenVPN-aware firewall.# eth0 is connected to the internet.# eth1 is connected to a private subnet.# Change this subnet to correspond to your private# ethernet subnet.  Home will use HOME_NET/24 and# Office will use OFFICE_NET/24.PRIVATE=10.0.0.0/24# Loopback addressLOOP=127.0.0.1# Delete old iptables rules# and temporarily block all traffic.iptables -P OUTPUT DROPiptables -P INPUT DROPiptables -P FORWARD DROPiptables -F# Set default policiesiptables -P OUTPUT ACCEPTiptables -P INPUT DROPiptables -P FORWARD DROP# Prevent external packets from using loopback addriptables -A INPUT -i eth0 -s $LOOP -j DROPiptables -A FORWARD -i eth0 -s $LOOP -j DROPiptables -A INPUT -i eth0 -d $LOOP -j DROPiptables -A FORWARD -i eth0 -d $LOOP -j DROP# Anything coming from the Internet should have a real Internet addressiptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROPiptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROPiptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROPiptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROPiptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROPiptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP# Block outgoing NetBios (if you have windows machines running# on the private subnet).  This will not affect any NetBios# traffic that flows over the VPN tunnel, but it will stop# local windows machines from broadcasting themselves to# the internet.iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROPiptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROPiptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROPiptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP# Check source address validity on packets going out to internetiptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP# Allow local loopbackiptables -A INPUT -s $LOOP -j ACCEPTiptables -A INPUT -d $LOOP -j ACCEPT# Allow incoming pings (can be disabled)iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT# Allow services such as www and ssh (can be disabled)iptables -A INPUT -p tcp --dport http -j ACCEPTiptables -A INPUT -p tcp --dport ssh -j ACCEPT# Allow incoming OpenVPN packets# Duplicate the line below for each# OpenVPN tunnel, changing --dport n# to match the OpenVPN UDP port.## In OpenVPN, the port number is# controlled by the --port n option.# If you put this option in the config# file, you can remove the leading '--'## If you taking the stateful firewall# approach (see the OpenVPN HOWTO),# then comment out the line below.iptables -A INPUT -p udp --dport 5000 -j ACCEPT# Allow packets from TUN/TAP devices.# When OpenVPN is run in a secure mode,# it will authenticate packets prior# to their arriving on a tun or tap# interface.  Therefore, it is not# necessary to add any filters here,# unless you want to restrict the# type of packets which can flow over# the tunnel.iptables -A INPUT -i tun+ -j ACCEPTiptables -A FORWARD -i tun+ -j ACCEPTiptables -A INPUT -i tap+ -j ACCEPTiptables -A FORWARD -i tap+ -j ACCEPT# Allow packets from private subnetsiptables -A INPUT -i eth1 -j ACCEPTiptables -A FORWARD -i eth1 -j ACCEPT# Keep state of connections from local machine and private subnetsiptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPTiptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTiptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPTiptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT# Masquerade local subnetiptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -