iptables入门教程--设置静态防火墙(step by step)[转帖]

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
bome爱
帖子: 23
注册时间: 2008-12-19 20:49

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#31

帖子 bome爱 » 2009-01-20 22:37

原来的回复是错误的,为免误导他人,特翻旧贴修改,各位见谅

iptables在-i后加 ! (感吧号),好像是排除规则
-i 后ppp0是ADSL拔号,若为eth0为网卡,可ifconfig查看得到
例:sudo iptables -A INPUT -i eth0 -p tcp --sport 80 -j ACCEPT

错误范例:sudo iptables -A INPUT -i! autoeth0 -p tcp --sport 80 -j ACCEPT
错误1:以为-i后是跟有线网络连接中设置的名称,如autoeth0、有线连接 1、(另一个是语言为英文时的名称,忘了)
正确:-i后应跟eth0(网卡)或ppp0(ADSL拔号)
错误2:由1而使-i后加 ! (感叹号)
正确:-i 一般不加 ! (感叹号),除故意添加排除规则

错误实例:
sudo iptables -A INPUT -i! autoeth0 -p tcp --sport 80 -j ACCEPT
sudo iptables -A INPUT -i! autoeth0 -p tcp -j REJECT --reject-with tcp-reset
sudo iptables -A INPUT -i! autoeth0 -p udp -j REJECT --reject-with icmp-port-unreachable
为什么这三条加上能正常浏览网页呢,原因是用-i!排除autoeth0这个外所有的都能用,自然eth0、ppp0都能用
上次由 bome爱 在 2009-07-14 18:20,总共编辑 1 次。
1.1.各主题下方提示条 或Ubuntu 命令(中文:wiki.ubuntu.org.cn/index.php?title=UbuntuSkills&variant=zh-cn
1.2.wiki(中文:wiki.ubuntu.org.cn
1.3.论坛/google/baidu等搜索
1.4.man+空格+命令 查看手册
wangtwo
帖子: 73
注册时间: 2007-05-07 9:42

Re:

#33

帖子 wangtwo » 2009-04-19 22:18

hcym 写了:正需要这个

测试防火墙

http://www.pcflank.com/test.htm

除了XP和Mac Leopard 过关, Ubuntu 没过

nnnnd
Results of the test:

Exploits test
Danger!

Your system successfully defended itself from this attack!

系统 Debian GNU/Linux lenny

:em09
lanky_ning
帖子: 2
注册时间: 2008-05-12 13:37

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#34

帖子 lanky_ning » 2009-09-26 9:59

今天看到这个帖子,正好用到,谢谢楼主了
dqwh
帖子: 7
注册时间: 2009-09-29 16:39

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#35

帖子 dqwh » 2010-06-04 23:25

thanks a lot. :em11
fwzxyyb
帖子: 3
注册时间: 2010-06-02 16:09

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#36

帖子 fwzxyyb » 2010-06-06 11:52

我很遗憾的告诉你写的是不错,但是这不是入门教程!

iptables 中的表有哪些?链有哪些?命令的规则等等有很多基础的东西,确实太多了...................
wuyinggz
帖子: 26
注册时间: 2007-10-25 10:01

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#37

帖子 wuyinggz » 2010-07-24 15:18

谢谢了 希望有更多像这样的教程
头像
linux5588
帖子: 305
注册时间: 2010-07-05 16:10
系统: Macos

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#38

帖子 linux5588 » 2010-10-04 11:06

LZ,,你把贴子完善下呀。。这不适合ubuntu,我在U里怎么启动iptables也不知道。
xd27303
帖子: 19
注册时间: 2010-09-08 23:35

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#39

帖子 xd27303 » 2011-03-20 22:24

顶顶。。。
学习中。。。。。
yiwan6
帖子: 59
注册时间: 2010-05-15 13:24

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#40

帖子 yiwan6 » 2011-03-27 20:40

作为发到ubuntu论坛的帖子,这里确实有问题。
最重要的一点:
当人家看着帖子想要一边实践的时候,却发现自己的配置完全无效。
明明已经封了80端口的,为什么还可以上网?!
首先得要启动防火墙
sudo modprobe iptables_filter
关闭防火墙的办法我也不知道,可以用ufw disable,但那不是我需要的答案。
自己动手,丰衣足食!
yiwan6
帖子: 59
注册时间: 2010-05-15 13:24

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#41

帖子 yiwan6 » 2011-03-28 14:17

ubuntu下关闭防火墙的办法,终于找到了。
看了网上的n多帖子都说在ubuntu下无法关闭防火墙。
但是在fedora下怎么就能够servcie iptables stop呢。
于是我在fedora下复制了一个/etc/init.d/iptables和/etc/init.d/functions 到ubuntu下。

functions是在iptables脚本里面调用的。
由于fedora下的许多配置文件和ubuntu下不一样,会有一些错误,但还是能够控制防火墙打打开关闭的。

阅读/etc/init.d/iptables发现,里面一个个检测,判断语句,十分复杂,但做的工作也还是那么几点。
就service iptales stop来说。
它最后关闭防火墙也是通过,sudo modprobe -r iptables_filter。
但在ubuntu下直接执行modprobe -r时却无法成功,会提示你防火墙正在使用中。
在移除模块之前,首先得
sudo iptables -F
sudo iptables -X
sudo iptables -Z

然后就可以成功移除模块了。
之前得将所有策略改为ACCEPT,这一步不是必须的,但最好做一下,有啥差别还不清楚。
:em11
自己动手,丰衣足食!
yangzhouem@139.com
帖子: 1
注册时间: 2011-04-03 16:31

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#43

帖子 yangzhouem@139.com » 2011-04-03 16:35

lz写得太棒了,我们这帮菜鸟有福了。 :em11
头像
seamonkey
帖子: 27
注册时间: 2012-07-17 23:02

Re: iptables入门教程--设置静态防火墙(step by step)[转帖]

#44

帖子 seamonkey » 2012-08-16 21:13

菜鸟表示很感谢
感觉比wiki上那个好多了
回复