关于Linux下的iptables
2015-07-29 13:04
549 查看
iptables -L -n /* 显示iptables列表 */
iptables -F /* 清除所有规则 --慎重操作*/
==============================================================================
编辑 vi /etc/sysconfig/iptables /*修改配置后,保存配置*/
iptables -A INPUT -p tcp --dport 22 -j ACCEPT /*允许包从22端口进入*/
iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT /*允许从22端口进入的包返回*/
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT /*允许本机访问本机*/
iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --dport 22 -j ACCEPT /*允许所有IP访问22端口*/
iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
保存修改配置 service iptables save
允许一系列IP地址访问
下面的命令可以允许IP地址范围
1.运行IP地址范围192.168.1.100 到192.168.1.200 访问22端口
# iptables -A INPUT -p tcp --destination-port 22 -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT
==============================================================================
firewall rules 防火墙的规则 其实就是保存在,查看 cat /etc/sysconfig/iptables
下面我只打开22端口,看我是如何操作的,就是下面2个语句
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
再查看下iptables -L -n
是否添加上去, 看到添加了
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:22
现在Linux服务器只打开了22端口,用putty测试一下是否可以登录成功。
通过命令:service iptables save
进行保存
==============================================================================
参考# http://www.csdn.net/article/2012-01-17/310905
iptables -F /* 清除所有规则 --慎重操作*/
==============================================================================
编辑 vi /etc/sysconfig/iptables /*修改配置后,保存配置*/
iptables -A INPUT -p tcp --dport 22 -j ACCEPT /*允许包从22端口进入*/
iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT /*允许从22端口进入的包返回*/
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT /*允许本机访问本机*/
iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --dport 22 -j ACCEPT /*允许所有IP访问22端口*/
iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
保存修改配置 service iptables save
允许一系列IP地址访问
下面的命令可以允许IP地址范围
1.运行IP地址范围192.168.1.100 到192.168.1.200 访问22端口
# iptables -A INPUT -p tcp --destination-port 22 -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT
==============================================================================
firewall rules 防火墙的规则 其实就是保存在,查看 cat /etc/sysconfig/iptables
下面我只打开22端口,看我是如何操作的,就是下面2个语句
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
再查看下iptables -L -n
是否添加上去, 看到添加了
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:22
现在Linux服务器只打开了22端口,用putty测试一下是否可以登录成功。
通过命令:service iptables save
进行保存
==============================================================================
参考# http://www.csdn.net/article/2012-01-17/310905
相关文章推荐
- 安装交叉编译器arm-none-linux-gnueabi-gcc
- Bumblebee解决Linux显卡问题 安装过后出现运行失败问题
- linux端口占用
- linux编译内核2.6.32.67
- 分析Linux内核创建一个新进程的过程
- 分析Linux内核创建一个新进程的过程
- Linux 系统启动流程详解
- linux rsync同步(续二)
- centos7 内存页面大小的设置
- du命令 实现Linux 某个文件夹下的文件按大小排序
- Linux SSH 登录其他机器
- linux netstat 笔记
- linux中的目录权限及文件权限
- linux下使用top命令查看系统运行状态和进程运行状态
- Linux下两种删除过期文件的方法详述
- linux expect远程自动登录以及执行命令
- 每天一个linux命令(3):pwd命令
- Linux环境下MySQL(二进制)自动安装脚本
- Linux 线程模型的比较:LinuxThreads 和 NPTL
- linux线程的线程ID与其进程ID