设为首页 收藏本站
查看: 565|回复: 0

[经验分享] setting up a firewall using Debian 2.2 and Kernels

[复制链接]

尚未签到

发表于 2018-5-16 07:19:44 | 显示全部楼层 |阅读模式
Welcome to Notes on setting up a firewall using Debian 2.2 and Kernels 2.4.xx

________________________________________

Here are the basic steps to setting up a firewalling computer
1) Setup the ethernet cards (NIC's).
2) Edit /etc/lilo.conf (as needed)
3) Setup the file /etc/init.d/network.
4) Setup the file /etc/resolv.conf.
5) Setup the file /etc/hosts.conf.
6) Setup the file /etc/hostname.
7) finish Setting up in /etc/init.d/inetd
8) Compiling in the forwarding and IMASQ support into the kernel (see the ipmasq howto for more details)
9) Additional work for a modem

Ethernet - Debian 2.1/2.2
Network Card (NIC)
Start by editing /etc/modutils and add NIC modules one per line eg.
tulip
3c509
Now reboot using one of these commands:init 6 or reboot or shutdown -r now
Modular Kernel
Modconf is now available in 2.4.5 kernels
Enabling IP forwarding
Now for Debian 2.0/1/2 we probably need to turn ip_forwarding on, check with this line first,
cat /proc/sys/net/ipv4/ip_forward
if this returns 1 then forwarding is already on if it returns 0 then you need to cd /etc/networks and open options eg nano options,
change ipforward=no to yes so IPforwarding will be available after boot. Now reboot to check ipforwarding is on.

Firewalling script for a firewall
Generally you want ip_forwarding and the firewall scripts to be available automatically at boot, to do this we create a firewall script.
First cd to /etc/init.d then type touch nat-fw-up followed by chmod 0755 nat-fw-up This creates an empty file ready to fill woth firewall rules.
Generally we want the firewall rules to start after everything else, so therefore type, update-rc.d nat-fw-up start 99 2 3 4 5 . (note the . on the end).
This puts a symbolic link from nat-fw-up to the run levels 2, 3, 4 & 5 so the firewall rules start when ever one of the 4 run levels is entered.
99 means that this will be one of the last rules started (01 would be one of the first).

nat-fw-up
Now to construct the firewall script, first start ip_forward, then allow NAT (Network Address Translation) finally firewall rulesets to protect the firewall and the computers behind it.
It should be noted that most iptable modules will load when the kernel detects the modules are called for however these can be called manually.
My script below has 3 network cards, therefore normally ignore lines for inner_nic2/eth2/inner_nw2.
#!/bin/bash
#iptables firewall script
#rev 2 17/06/01
#rev 3 20/11/01 ipsec input rules added and tightened
#rev 4 8/12/01 Rule to allow netbios over ipsec added.
#rev 5 8/12/01 tidy up some unclean & invalid etc with rules

#start ip_forwarding
#echo "1" > /proc/sys/net/ipv4/ip_forward
#echo "forwarding started"
#started in /etc/network/options

#set constants
outer_nic="eth0"
inner_nic1="eth1"
inner_nic2="eth2"
inner_nw1="172.31.0.0/16"
rh_fwall="192.168.1.253"
lh_fwall="192.168.1.254"
#inner_nw1="192.168.0.0/24"
#inner_nw2="10.0.0.0/8"
#web="172.31.0.16:80"
#web="172.16.0.20:80"
#smtp="172.16.0.20:25"
#web="192.168.0.100:80"
#ident="10.0.0.2:113"
echo "firewall constants setup"

#load any modules needed for connection tracking
#allow passive ftp
/sbin/modprobe ip_conntrack_ftp
#irc module
#/sbin/modprobe ip_conntrack_irc
#/sbin/modprobe
echo "started connection tracking"

#individual port forwarding
#www
#iptables -A PREROUTING -t nat -p tcp -i $outer_nic --dport 80 \
#-j DNAT --to $web
#smtp
#iptables -A PREROUTING -t nat -p tcp -i $outer_nic --dport 25 \
#-j DNAT --to $smtp
#ident
#iptables -A PREROUTING -t nat -p tcp -i $outer_nic --dport 113 \
#-j DNAT --to $ident
#--to $ident
iptables -A PREROUTING -t nat -i eth0 -d $inner_nw1 -j Drop
#iptables -A PREROUTING -t nat -i eth0 -d $inner_nw2 -j Drop
echo "no portfw started"
#echo "portfw started"

#forward rules
iptables -t nat -A POSTROUTING -s $inner_nw1 -o $outer_nic -j MASQUERADE
#iptables -t nat -A POSTROUTING -s $inner_nw1 -o inner_nic2 \
#-j MASQUERADE
iptables -A FORWARD -i $inner_nic1 -j ACCEPT
#iptables -A FORWARD -i $inner_nic2 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
#ipsec rule for NETBIOS/SAMBA over the tunnel
iptables -A FORWARD -i ipsec0 -j ACCEPT
#clean up a bad syn which needs a specific rule
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j Drop
#clean these up as well
iptables -A FORWARD -m state --state INVALID -j Drop
iptables -A FORWARD -m unclean -j Drop
#Final default policy
iptables -P FORWARD Drop
echo "FORWARD rules now in place"

#INPUT rules
#specific ipsec lines
iptables -A INPUT -s $lh_fwall -p udp --dport 500 -j ACCEPT
iptables -A INPUT -s $lh_fwall -p 50 -j ACCEPT
iptables -A INPUT -s $lh_fwall -p 51 -j ACCEPT
echo "ipsec rules in place"

#general
iptables -A INPUT -p tcp --syn --dport 22 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! $outer_nic -j ACCEPT
#allow ping replies (may not be desired)
iptables -A INPUT -p icmp -s 0/0 --icmp-type echo-request -j ACCEPT
iptables -P INPUT Drop
echo "INPUT rules now in place"

#limit logging levels to save clutter and /var from being swamped
#iptables -A FORWARD -m limit --limit 3/m -j LOG
#iptables -A FORWARD -j LOG
echo "log limiting in place"

#specific defence rules eg DoS attacks
#syn-flood protection
iptables -A FORWARD -p tcp --syn -m limit  -j ACCEPT
#furtive port scanner
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit
#ping of death
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit
echo "DoS defences setup"

exit
This is a basic setup and probably needs further work, however after tests with nmap and various other attacks it does look secure.

Firewalling script for a host
*************NB*****THIS****HAS***NOT****BEEN****TESTED****YET!**********
Generally you want ip_forwarding turned off and the firewall scripts to be available automatically at boot,
to do this we create a firewall script and make sure forwarding is off in /etc/network/options.
First cd to /etc/init.d then type touch nat-fw-up followed by chmod 0755 nat-fw-up This creates an empty file ready to fill woth firewall rules.
Generally we want the firewall rules to start after everything else, so therefore type, update-rc.d nat-fw-up start 99 2 3 4 5 . (note the . on the end).
This puts a symbolic link from nat-fw-up to the run levels 2, 3, 4 & 5 so the firewall rules start when ever one of the 4 run levels is entered.
99 means that this will be one of the last rules started (01 would be one of the first).

nat-fw-up
#!/bin/bash
#NAT iptables rule
#NB this script is not secure its still being worked on!
#ssj 6/10/01
#NB this has not been tested yet! its an example!

#setup some constants

outer_nic="eth0"
echo "firewall constants setup"

#load any modules needed for connection tracking
#allow passive ftp
/sbin/modprobe ip_conntrack_ftp
echo "started connection tracking"

#FORWARD rules
iptables -P FORWARD Drop
echo "FORWARD rules now in place."

#INPUT rules
#allow ssh to the firewall from any NIC
iptables -A INPUT -p tcp --syn --dport 22 -j ACCEPT
#enable these as needed for services (some may need to be tcp and udp eg Netbios)
#iptables -A INPUT -p tcp --syn --dport 25 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 80 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 110 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 113 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 137 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 138 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 139 -j ACCEPT
#iptables -A INPUT -p tcp --syn --dport 143 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#allow ping replies (may not be wanted)
iptables -A INPUT -p ICMP -s 0/0 --icmp-type echo-request -j ACCEPT
iptables -P INPUT Drop
echo "INPUT rules now in place."

#limit logging levels
iptables -A FORWARD -m limit -j LOG
echo "log limiting in place"

#specific defence rules eg DoS attacks
#syn-flood protection
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
#furtive port scanner
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit \
--limit 1/s -j ACCEPT
#ping of death
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit \
--limit 1/s -j ACCEPT
echo "Dos defences set up."

exit



Copyright Thing 8/12/2001 to be used freely without restriction,
however if this page is copied to your own web site please drop me a line with the URL - thanks.
The Debian logo is a trademark of Debian, who in no way endorse or take responsibility for information on this site.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-460750-1-1.html 上篇帖子: Debian sarge 3.1r1 在Intel se7320ep2 主板上的安装 下篇帖子: debian(ubuntu)下编译内核简介
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表