iptables防火墙

 1.简单写一个网页

下载nginx

setenforce 0
systemctl stop firewalld
systemctl disable firewalld
yum install nginx -y

启动

 systemctl start nginx

编写网页内容

mkdir -p /www/haha

echo "hello world" >/www/haha/index.html

vim /etc/nginx/conf.d/vshost.conf
server{
        listen  80;
        server_name 192.168.132.129;
        root /www/haha;
}

重启

systemctl restart nginx

1、安装iptables

yum install -y iptables-services

2、关闭firewalld,开启iptables

systemctl stop firewalld

systemctl start iptables

3、添加规则:ssh服务端口22,dns服务53,httpd服务80,chrony服务123,nfs服务111

iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 123 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 111 -j ACCEPT

4、添加一条拒绝所有

iptables -t filter -A INPUT -p ip -j REJECT

由于匹配原则从上至下依次匹配最后一条为拒绝所有所以最后会拒绝

5、查看规则表

iptables -vnL --line-numbers

6、清空所有的规则表

iptables -F
  • table有优先级:由高到低排列为:raw -> mangle -> nat -> filter
  • 当有多个table包含同一类型的chain时,所有的table都会按照上面table优先级被遍历,执行table中实际的chain下的规则。
  • 注意不要直接在第一条就拒绝所有,负责会坏掉
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值