AI编程生活评测

Centos常用命令记录之:iptables

编程笔记 / 2018-02-01 / 1 min
Centos 防火墙的设置,在 Centos 7 之前的版本中大量都是在使用 iptables ,项目服务器的运维上急需相关知识;
  • 首先,记住 iptables 的配置文件的位置 /etc/sysconfig/iptables ,修改前最好备份一下;

iptables相关命令:

  • 查看现有的iptables规则:
service iptables status
Table: filter
Chain INPUT (policy DROP)
num  target     prot opt source           destination         
1    ACCEPT     tcp  --  0.0.0.0/0        0.0.0.0/0       state NEW tcp dpt:8090 
2    ACCEPT     tcp  --  0.0.0.0/0        0.0.0.0/0       state NEW tcp dpt:3306 
3    ACCEPT     tcp  --  0.0.0.0/0        0.0.0.0/0       state NEW tcp dpt:80 
4    ACCEPT     tcp  --  0.0.0.0/0        0.0.0.0/0       state NEW tcp dpt:22 
5    ACCEPT     tcp  --  0.0.0.0/0        0.0.0.0/0       state NEW tcp dpt:21 
6    ACCEPT     icmp --  0.0.0.0/0        0.0.0.0/0       icmp type 255 
7    ACCEPT     all  --  127.0.0.1        127.0.0.1           
8    ACCEPT     all  --  0.0.0.0/0        0.0.0.0/0       state RELATED,ESTABLISHED 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
  • 添加/插入规则
#使用A(ADD)命令在规则的结尾添加一条
iptables -A
#使用I(INSERT)命令在指定位置插入一条
iptables -I
  • 删除现有的规则,删除上面INPUT表中的序号为1的规则:
iptables -D INPUT 1
  • 保存规则
service iptables save
  • 重载规则
service iptables restart
这些就是基本的iptables操作了。
  1. typecho模板 2018-02-28 · 00:08

    最近在恶补Linux命令,熟练之后就要上vps了,现在主机太多管理起来麻烦死了

    1. 行星带 2018-03-20 · 08:56

      迟早的事情,虚机不确定性太多了