Linux网络相关、firewalld和netfilter,netfilter5表5链介绍,iptables语法

linux网络相关

• ifconfig查看网卡ip(yum install net-tools)
• ifup ens33/ifdown ens33
• 设定虚拟网卡ens33:1
• mii-tool ens33 查看网卡是否连接
• ethtool ens33 也可以查看网卡是否连接
• 更改主机名 hostnamectl set-hostname aminglinux
• DNS配置文件/etc/resolv.conf
• /etc/hosts文件

ifconfig 查看网卡的IP,centos6默认就有,centos7没有,需要安装一个包net-tools
yun install -y net-tool

215553_wV3v_3791387.png

ip add 也可以查看网卡

215614_yfjV_3791387.png

ifconfig -a 在你网卡宕掉的时候或者没有IP的时候,ifconfig是查看不了的,用-a是可以查看到的。

ifdown ens33 关闭和启动网卡ens33

215733_RBTA_3791387.png

ifdown ens33;ifup ens33 这个命令在那些情况下使用呢?
在针对某个网卡进行更改,比如DNS等,更改完后需要重启服务,但是我不想把所有的网卡都重启,这个时候,就可以使用ifdown和ifup来单独重启这个网卡.

ifdown ens33 &&ifup ens33 重启网卡

215747_FDZw_3791387.png

增加一个ip怎么做呢?
首先增加一个虚拟网卡,在虚拟网卡上添加一个IP
先到网卡配置文件里面,拷贝一个虚拟网卡

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-enss ifcfg-enss\:0
[root@localhost network-scripts]# vim ifcfg-ens33:0  

220154_PgdU_3791387.png

重启下网卡

# ifdown ens33 &&ifup ens33   

220302_J7yT_3791387.png

在window上ping这个IP

220401_nE4v_3791387.png

虚拟网卡会在lvs,keepalived 上用到。

查看某台电脑网线是否正常 mii-tool ens33

220502_e7Zp_3791387.png

如果mii-tool 提示no link 可以用ethtool 来查看网卡是否正常
输入图片说明

也可以用 ethtool ens33 来查看网卡是否正常

220601_az1M_3791387.png

hostnamectl set-hostname aminglinux 更改主机名 centos7独有的

[root@yong-02 ~]# hostnamectl set-hostname yongge-02

hostname 查看主机名

[root@yong-02 ~]# hostname
yongge-02

主机名的配置文件 /etc/hostname

[root@yong-02 ~]# cat /etc/hostname
yongge-02


如果想要生效,可以重新登录一下

DNS的配置文件 /etc/resolv.conf
220901_Cb19_3791387.png
dns是在配置网卡的时候写的。配置文件里面修改DNS是临时的,重启后就不能生效了,所以要去网卡配置里面修改DNS。

域名解析 /etc/hosts 只在本机上生效 加入192.168.180.135 www.qq.com 解析到本机IP

221029_jBnt_3791387.png

221052_Uk8Y_3791387.png

可以一个IP多个域名;用空格隔开 ;
如果是一个域名多个IP,只生效最后IP.

linux防火墙-netfilter

• selinux临时关闭 setenforce 0
• selinux永久关闭 vi /etc/selinux/config
• centos7之前使用netfilter防火墙
• centos7开始使用firewalld防火墙
• 关闭firewalld开启netfilter方法
• systemctl stop firewalld
• systemctl disable firewalled
• yum install -y iptables-services
• systemctl enable iptables
• systemctl start iptables

永久关闭selinux

编辑配置文件 /etc/selinux/config,SELINUX=disabled ,然后重启服务
输入图片说明

临时关闭selinux setenforce 0

221439_zt8X_3791387.png

Enforcing 强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了
Permissive 宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取
disabled:关闭,SELinux 并没有实际运作。

linux防火墙 netfilter是centos5,6自带的
linux防火墙 firewalld是centos7的自带的

centios7里面也可以使用 netfilter,那么怎么使用呢?

1)首先关闭contos7自带的firewalld
systemctl disable firewalld

221627_v0RG_3791387.png

2)关闭服务

systemctl stop firewalld

3)打开netfilter,打开前先安装一个包 iptables-services

yum install -y iptables-services

4)开启服务

systemctl enable iptables

systemctl start iptables

5)iptables -nvL 查看规则

222157_AbXx_3791387.png

 

Linux防火墙—netfilter

  • netfilter的5个表
  • filter表用于过滤包,最常用的表,有INPUT、FORWARD、OUTPUT三个链
  • nat表用于网络地址转换,有PREROUTING、POSTROUTING三个链
  • managle表用于给数据包做标记,几乎用不到
  • raw表可以实现不追踪某些数据包
  • security表在centos6中并没有,用于强制访问控制(MAC)的网络规则
  • 参考文章

netfilter的五个表

  • 在centos中只有四个表,并没有security表
[root@yong-02 ~]# man iptables

查看五个表
              filter:
                  This is the default table (if no -t option is passed). It  contains
                  the  built-in chains INPUT (for packets destined to local sockets),
                  FORWARD (for packets being routed through the box), and OUTPUT (for
                  locally-generated packets).

              nat:
                  This table is consulted when a packet that creates a new connection
                  is encountered.  It consists of three  built-ins:  PREROUTING  (for
                  altering  packets  as  soon  as they come in), OUTPUT (for altering
                  locally-generated packets before  routing),  and  POSTROUTING  (for
                  altering packets as they are about to go out).  IPv6 NAT support is
                  available since kernel 3.7.

              mangle:
                  This table is used for specialized packet alteration.  Until kernel
                  2.4.17  it had two built-in chains: PREROUTING (for altering incom‐
                  ing packets before routing) and OUTPUT (for altering locally-gener‐
                  ated  packets  before  routing).   Since kernel 2.4.18, three other
                  built-in chains are also supported: INPUT (for packets coming  into
                  the box itself), FORWARD (for altering packets being routed through
                  the box), and POSTROUTING (for altering packets as they  are  about
                  to go out).

              raw:
                  This  table  is used mainly for configuring exemptions from connec‐
                  tion tracking in combination with the NOTRACK target.  It registers
                  at  the  netfilter  hooks  with  higher priority and is thus called
                  before ip_conntrack, or any other IP tables.  It provides the  fol‐
                  lowing  built-in  chains:  PREROUTING (for packets arriving via any
                  network interface) OUTPUT (for  packets  generated  by  local  pro‐
                  cesses)

              security:
                  This  table  is  used for Mandatory Access Control (MAC) networking
                  rules, such as those enabled by the SECMARK  and  CONNSECMARK  tar‐
                  gets.   Mandatory  Access  Control is implemented by Linux Security
                  Modules such as SELinux.  The security table is  called  after  the
                  filter table, allowing any Discretionary Access Control (DAC) rules
                  in the filter table to take effect before MAC  rules.   This  table
                  provides  the  following built-in chains: INPUT (for packets coming
                  into the box itself), OUTPUT (for altering locally-generated  pack‐
                  ets before routing), and FORWARD (for altering packets being routed
                  through the box).

  • filter表,就是默认的一个表,包含了三个内置的链:INPUT、FORWARD、OUTPUT
    • INPUT链,表示数据进来的包进来要经过的一个链,进入到本机
      • 比如,进入到本机后,将80端口进来的数据包,访问80端口的数据包检查下它的原IP是什么,发现可疑的IP需要禁掉
    • FORWARD链,这个数据包到了机器,并不会进入内核里,因为这个这数据包不是给你处理的,而是给另外一台机器处理的,所以这时候需要判断下你的目标地址是否为本机,如果不是本机,则需要经过FORWARD这个链
      • 在经过 FORWARD链的时候,也会做一些操作,把目标地址做一些更改,或者做一个转发
    • OUTPUT链,是在本机产生的一些包,在出去之前做的一些操作
      • 比如,这个包是发给某一个IP的,这个IP我要禁掉,不让这个包过去(已加入到黑名单),只要是到那个IP的,都给禁掉。
  • nat表,也有三个链PREROUTING 、OUTPUT、POSTROUTING
    • PREROUTING链,这个链用来更改这个数据包——>在进来的那一刻就去更改
    • OUTPUT链,它和上面filter表中的OUTPUT链是一样的
    • POSTROUTING链,这个链也是更改数据包——>在出去的那一刻更改
  • nat表,使用案列
    • 路由器的实现的共享上网就是nat实现的
    • 端口映射
  • mangle表和raw表和security表几乎用不到

参考文章

  • 参考文章
  • iptables传输数据包的过程
    • ① 当一个数据包进入网卡时,它首先进入PREROUTING链,内核根据数据包目的IP判断是否需要转送出去。
    • ② 如果数据包就是进入本机的,它就会沿着图向下移动,到达INPUT链。数据包到了INPUT链后,任何进程都会收到它。本机上运行的程序可以发送数据包,这些数据包会经过OUTPUT链,然后到达POSTROUTING链输出。
    • ③ 如果数据包是要转发出去的,且内核允许转发,数据包就会如图所示向右移动,经过FORWARD链,然后到达POSTROUTING链输出。

输入图片说明

  • 总结:
  1. 如果是本机的,则会经过PREROUTING链--->INPUT链--->OUTPUT链--->POSTROUTING链
  2. 如果不是本机的,则会经过PREROUTING链--->FORWARD链--->POSTROUTING链

iptables语法

  • 查看iptables规则:iptables -nvL
  • iptables -F 清空规则
  • service iptables save 保存规则
  • iptables -t nat 参数-t 指定表
  • iptables -Z 可以把计数器清零
  • iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP
  • iptables -I/-A/-D INPUT -s 1.1.1.1 -j DROP
  • iptables -I INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT
  • iptables -nvL --line-numbers
  • iptables -D INPUT 1
  • iptables -P INPUT DROP

iptables命令

  • iptables -nvL 查看iptables默认规则
[root@yong-02 ~]# iptables -nvL   //查看iptables规则
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  357 28956 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    2   184 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
   18  1404 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 251 packets, 57368 bytes)
 pkts bytes target     prot opt in     out     source               destination         
[root@hf-01 ~]# 

  • service iptables restart 重启iptables规则
[root@yong-02 ~]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service
  • 存放默认规则的位置
    • /etc/sysconfig/iptables
[root@yong-02 ~]# cat /etc/sysconfig/iptables   //存放默认规则的位置
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-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 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

iptables -F清空规则

  • iptables -F清空规则
    • 在清空规则后,再去查看,会发现没有规则了(但是在文件中依旧保存这规则)
[root@yong-02 ~]# iptables -F 
[root@yong-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 14 packets, 924 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 8 packets, 768 bytes)
 pkts bytes target     prot opt in     out     source               destination   
  • service iptables save 保存规则

    • 若是在清空规则后,去执行service iptables save保存规则,那存放规则的文件也会变成所保存的规则
  • 在iptables -F清空规则后,重启service restart iptables.service(重启服务器或者iptables规则),都会加载配置文件里面的规则

    • 在重启规则后,会看到原先被清空的规则重新加载了
[root@yong-02 ~]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service
[root@yong-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    6   396 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.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:22
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 4 packets, 480 bytes)
 pkts bytes target     prot opt in     out     source               destination  
  • iptables -t nat -nvL 查看nat表中的规则
    • 在不指定表的时候,默认就是 filter 表

iptables -Z 把计数器清零

  • iptables -Z 把计数器清零
    • 在查看filter表的时候,会看到第一列和第二列都是有数据的
      • 第一列,是有多少个包
      • 第二列,是数据量,数据大小(单位:bytes字节)
[root@yong-02 ~]# iptables -Z ; iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.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:22
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination 

  • 这里会看到数字都清零了,但过一会再来查看,会看到数字又出现了(因为在每时每刻都在通信)
[root@yong-02 ~]# iptables -t filter -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    4   280 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.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:22
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 3 packets, 1396 bytes)
 pkts bytes target     prot opt in     out     source               destination

iptables新增规则 -A

  • 在iptables命令中,没有-t 指定表的时候,默认就是filter表
  • iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP
    • -A,就是增加一条规则(这里针对的是INPUT链)
      • 新增的规则会在规则的最后面
    • -s ,指定来源IP
    • -p,指定它的协议,是TCP,还是UDP,或者是ICMP协议
    • -sport,来源的端口
    • -d,指目标的IP
    • -dport,指目标的端口
    • -j,操作
    • DROP,扔掉
    • REJECT,拒绝
  • DROP扔掉和REJECT拒绝,最终实现的效果是一样的,都是为了让数据包过不来,相当于把IP给封掉
  • DROP和REJECT区别:
    • DROP,在这个数据包来了之后,看都不看直接扔掉
    • REJECT,在这个数据包来了之后,先看一看,看完之后,在拒绝
[root@yong-02 ~]# iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP      //新增规则
[root@yong-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   21  1508 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.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:22
    1   229 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    0     0 DROP       tcp  --  *      *       192.168.188.1        192.168.188.128      tcp spt:1234 dpt:80

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 6 packets, 872 bytes)
 pkts bytes target     prot opt in     out     source               destination   

iptables命令 参数 -I  插入 insert

  • iptables -I INPUT -p tcp --dport 80 -j DROP
    • 这里是简写,不指定来源IP,和目标IP,只写目标的端口——>但一定要指定tcp/ip
    • 若是使用了 dport 或 sport ,那么前面必须 -p 指定它的协议
[root@yong-02 ~]# iptables -I INPUT -p tcp --dport 80 -j DROP
[root@yong-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
   32  2276 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.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:22
    1   229 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    0     0 DROP       tcp  --  *      *       192.168.188.1        192.168.188.128      tcp spt:1234 dpt:80

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 4 packets, 512 bytes)
 pkts bytes target     prot opt in     out     source               destination   
[root@hf-01 ~]# 
  • -I和-A的区别:
    • -I,表示插入
    • -A,表示增加
  • 若是规则添加到前面,则是优先过滤最前面的规则,然后再去往下一条条的执行
    • 若是数据包匹配了第一条规则(同时满足两条规则),就会先匹配第一条规则。一旦匹配了第一条规则,那么数据包就会被抓取掉了,就不会再往下执行规则了
    • 一旦匹配规则,立即执行

iptables命令参数-d 删除规则

  • iptables -D INPUT -s 1.1.1.1 -j DROP 删除规则
[root@yong-02 ~]# iptables -D INPUT -p tcp --dport 80 -j DROP   //删除规则
[root@yong-02 ~]# iptables -D INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP     //删除规则
[root@yong-02 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  243 18884 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.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:22
    2   462 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 5 packets, 908 bytes)
 pkts bytes target     prot opt in     out     source               destination 
根据编号删除规则
  • 删除规则的另一种方法
  • iptables -nvL --line-numbers 打印出规则的序列号
    • 第一列就是number
[root@yong-02 ~]# iptables -nvL  --line-number
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1      396 31108 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
2        0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
3        0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
4        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
5        2   462 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
6        0     0 DROP       tcp  --  *      *       192.168.188.1        192.168.188.128      tcp spt:1234 dpt:80

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 4 packets, 656 bytes)
num   pkts bytes target     prot opt in     out     source               destination                  
[root@yong-02 ~]# iptables -D INPUT 6    //删除序列6的规则
[root@yong-02 ~]# iptables -nvL  --line-number
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1      455 35012 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
2        0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
3        0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
4        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
5        2   462 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 4 packets, 432 bytes)
num   pkts bytes target     prot opt in     out     source               destination

iptables命令 参数 -P

  • iptables -P OUTPUT DROP 默认的规则

    • 链中,有一个默认的策略policy,policy ACCEPT表示这个链不加这些规则的话,那OUTPUT没有任何的规则,所以对于OUTPUT链的数据包来讲,policy ACCEPT就是由默认的策略来决定的
      • 默认的策略是由ACCEPT来决定,所有的数据包只要是没有具体的规则来匹配,那么它就走默认的策略
  • 默认的规则最好不要去改变!!!

转载于:https://my.oschina.net/u/3791387/blog/1808826

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值