百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> Linux下防火墙iptables学习笔记
分享文章到:

Linux下防火墙iptables学习笔记

发布时间:01/15 来源: 浏览: 关键词:
iptables是防火墙,它只用于linux内核系统了,对于学linux的朋友防火墙是必须要学习了解的,下面我们来看看小编整理的一篇Linux下防火墙iptables学习笔记,希望例子能够对各位有帮助。


一、iptables的开启和关闭

1. 重启系统生效


[Sun@webserver2 ~]$ sudo chkconfig iptables on     开启
[Sun@webserver2 ~]$ sudo chkconfig iptables off    关闭

2.即时生效,重启系统后失效


[Sun@webserver2 ~]$ sudo service iptables start    开启
[Sun@webserver2 ~]$ sudo service iptables stop     关闭

二、查看iptables配置

[Sun@webserver2 ~]$ sudo iptables -L -n

三、开放指定的端口

每次修改后重启iptables服务生效

1.允许本地回环接口(即运行本机访问本机)
1
[Sun@webserver2 ~]$ sudo iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

2.允许访问80端口(web服务器常用端口)


[Sun@webserver2 ~]$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

3.允许访问22端口(ssh端口)


[Sun@webserver2 ~]$ sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

4.允许访问3306端口(MySQL端口)


[Sun@webserver2 ~]$ sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT

5.允许访问21和20端口(FTP服务器端口)


[Sun@webserver2 ~]$ sudo iptables -A INPUT -p tcp --dport 20 -j ACCEPT
[Sun@webserver2 ~]$ sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT

6.允许所有本机向外的访问

[Sun@webserver2 ~]$ sudo iptables -A OUTPUT -j ACCEPT

四、屏蔽IP

每次修改后重启iptables服务生效

1.屏蔽单个IP


[Sun@webserver2 ~]$ sudo iptables -I INPUT -s 123.45.6.7 -j DROP

2.屏蔽从123.0.0.1到123.255.255.254网段

[Sun@webserver2 ~]$ sudo iptables -I INPUT -s 123.0.0.0/8 -j DROP

3.屏蔽从123.1.0.1到123.1.255.254网段

[Sun@webserver2 ~]$ sudo iptables -I INPUT -s 123.1.0.0/16 -j DROP

4.屏蔽从123.1.2.1到123.1.2.254网段


[Sun@webserver2 ~]$ sudo iptables -I INPUT -s 123.1.2.0/24 -j DROP

五、删除已添加的iptables规则
每次修改后重启iptables服务生效

1.将所有iptables以序号标记显示

[Sun@webserver2 ~]$ sudo iptables -L -n --line-numbers

2.执行删除序号为1的

1
[Sun@webserver2 ~]$ sudo iptables -D INPUT 1
 

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有6人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板