转:db2 iptables相关用法(2)

Centos 6 iptables 配置

Ben

2011/12/24

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2256

2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

7    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

-----------

插入1条记录

[[email protected] ben.liu]# iptables -I INPUT -j ACCEPT -s 172.16.0.0/16 -p tcp --dport 443 -m state --state NEW

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     tcp  --  172.16.0.0/16        0.0.0.0/0           tcp dpt:443 state NEW

2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2256

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

4    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

8    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

-

[[email protected] ben.liu]# iptables-save

# Generated by iptables-save v1.4.7 on Sat Dec 24 16:50:09 2011

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [201:20052]

-A INPUT -s 172.16.0.0/16 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 2256 -j ACCEPT

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

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

# Completed on Sat Dec 24 16:50:09 2011

--

修改1条记录:比如第7条   state NEW tcp dpt:22

[[email protected] ben.liu]# iptables -R INPUT 7 -s 172.16.0.0/16 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

[[email protected] ben.liu]# iptables status

Bad argument `status‘

Try `iptables -h‘ or ‘iptables --help‘ for more information.

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     tcp  --  172.16.0.0/16        0.0.0.0/0           tcp dpt:443 state NEW

2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2256

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

4    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

7    ACCEPT     tcp  --  172.16.0.0/16        0.0.0.0/0           state NEW tcp dpt:22

8    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

--

删除1条记录,比如:第7条

[[email protected] ben.liu]# iptables -D INPUT 7

[[email protected] ben.liu]# iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination

ACCEPT     tcp  --  172.16.0.0/16        anywhere            tcp dpt:https state NEW

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:pcc-mfp

ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

ACCEPT     icmp --  anywhere             anywhere

ACCEPT     all  --  anywhere             anywhere

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http

REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination

REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination

[[email protected] ben.liu]# iptables -L -n

Chain INPUT (policy ACCEPT)

target     prot opt source               destination

ACCEPT     tcp  --  172.16.0.0/16        0.0.0.0/0           tcp dpt:443 state NEW

ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2256

ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination

REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     tcp  --  172.16.0.0/16        0.0.0.0/0           tcp dpt:443 state NEW

2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2256

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

4    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

7    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

---

清空所有INPUT 记录

[[email protected] ben.liu]# iptables-save > /etc/sysconfig/iptables.bak

[[email protected] ben.liu]# iptables -F INPUT

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

[[email protected] ben.liu]# iptables-save > /etc/sysconfig/iptables.bak

[[email protected] ben.liu]# iptables -F INPUT

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

恢复以前保存的记录:

[[email protected] ben.liu]# iptables-restore /etc/sysconfig/iptables.bak

[[email protected] ben.liu]# service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    ACCEPT     tcp  --  172.16.0.0/16        0.0.0.0/0           tcp dpt:443 state NEW

2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2256

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

4    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0

5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80

7    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination

[[email protected] ben.liu]# iptables-save

# Generated by iptables-save v1.4.7 on Sat Dec 24 17:24:57 2011

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [44:5152]

-A INPUT -s 172.16.0.0/16 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 2256 -j ACCEPT

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

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

# Completed on Sat Dec 24 17:24:57 2011

----------

查看iptables 启动的规则文件:

[[email protected] ben.liu]# cat /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

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

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

---

关闭/ 禁止、允许随系统启动/启动/重启/   iptables服务

[[email protected] ben.liu]# service iptables stop

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]

[[email protected] ben.liu]# chkconfig --level 35 iptables off

[[email protected] ben.liu]# chkconfig --level 35 iptables on

[[email protected] ben.liu]# service iptables start

iptables: Applying firewall rules:                         [  OK  ]

[[email protected] ben.liu]# service iptables restart

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]

iptables: Applying firewall rules:                         [  OK  ]

时间: 2024-08-02 03:30:57

转:db2 iptables相关用法(2)的相关文章

转:db2 iptables相关用法

如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [[email protected] ~]# iptables -L -nChain INPUT (policy ACCEPT)target       prot opt source                 destination Chain FORWARD (policy ACCEPT)target       prot opt s

CentOS 7.x 防火墙开放端口相关用法记录

CentOS 7.x 防火墙开放端口相关用法记录 前言 防火墙对服务器起到一定的保护作用,所以了解一些相关的操作是很有必要的. 在CentOS 7.x中,有了一种新的防火墙策略,FireWall , 还记得在6.x中用的还是iptables. 这几天一直在自己的服务器上瞎搞,由于关于这个防火墙的命令还没有烂熟于心,每次都需要google一下,所以就自己动手整理了一下,方便今后的使用也同时加强记忆. 基本命令 在CentOS 7.x中,防火墙的基本命令是 firewall-cmd 先通过man f

实现vsftp虚拟用户和iptables基本用法

1.搭建vsftpd服务器 1.安装vsftpd服务 [root@centos7 ~]#yum install -y vsftpd 2.启动服务 [root@centos7 ~]#systemctl start vsftpd [root@centos7 ~]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 5 192.168.122.1:53 *:*

Js相关用法个人总结

Js相关用法个人总结  js中将数组元素添加到对象中var obj = {}; var pushArr = [11,22,33,44,55,66]; for(var i=0;i<pushArr.length;i++) { obj[i] = pushArr[i]; } obj.length = pushArr.length; console.log(obj); //{0:11,1:22,2:33,3:44,4:55,5:66,length:6} 在js中为对象添加属性和方法 var obj = {

STL中的Vector相关用法

STL中的Vector相关用法 标准库vector类型使用需要的头文件:#include <vector>. vector 是一个类模板,不是一种数据类型,vector<int>是一种数据类型. Vector的存储空间是连续的,list不是连续存储的. 1. 定义和初始化 vector< typeName > v1; //默认v1为空,故下面的赋值是错误的v1[0]=5;//v2是v1的一个副本,若v1.size()>v2.size()则赋值后v2.size()被

MyEclipse相关用法介绍

MyEclipse相关用法介绍 ================================================================================ 编辑: Ctrl+Shift+L      显示所有快捷键 Ctrl+K        参照选中的词(Word)快速定位到下一个 Ctrl+Shift+K      参照选中的词(Word)快速定位到上一个 Ctrl+O         快速显示OutLine Ctrl+T        快速显示当前类的

#ifdef预编译相关用法

#ifdef预编译相关用法主要有:(1)#ifdef XXX executing the corresponding xxx code #endif(2)#ifdef XXX executing the corresponding xxx code #else executing the other code(3)#ifdef XXX executing the corresponding xxx code #elifdef YYY executing the corresponding yyy

Java中Date各种相关用法

Java中Date各种相关用法(一) 1.计算某一月份的最大天数 Java代码 Calendar time=Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR,year); time.set(Calendar.MONTH,i-1);//注意,Calendar对象默认一月为0 int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天数 注:在使用set方法之前,必须

Python中的Scrapy 命令相关用法

Python语言中Scrapy 命令是非常重要的一个命令,今天和大家分享的就是Scrapy 命令的相关用法.Scrapy 命令分为两种: 全局命令和项目命令,具体的用法,一起来看看吧 . 全局命令:在哪里都能使用. 项目命令:必须在爬虫项目里面才能使用. 全局命令 C:\\Users\\AOBO>scrapy -h Scrapy 1.2.1 - no active project Usage: scrapy[options] [args] Available commands: bench Ru