知了堂|iptables与firewalld 防火墙操作配置

一.iptables 防火墙配置

(1)为 filter 表的 INPUT 链添加一条规则,规则为拒绝所有使用 ICMP 协议的数据包。★★

iptables -A INPUT -p icmp -j DROP 将数据包丢弃,不回应

REJECT 丢弃并回应

(2)为 filter 表的 INPUT 链添加一条规则,规则为允许访问 TCP 协议的 80 端口的数据包通过。★★

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

(3)在 filter 表中 INPUT 链的第 2 条规则前插入一条新规则,规则为不允许访问 TCP。协议的 53 端口的数据包通

过。★★

查看:iptables -L -n --line-number

(显示规则的序号:num)

iptables -I INPUT 2 -p tcp --dport 53 -j DROP

(4)在 filter 表中 INPUT 链的第 1 条规则前插入一条新规则,规则为允许源 IP 地址属于 172.16.0.0/16 网段的数

据包通过。★★★

iptables -I INPUT 1 -s 172.16.0.0/16 -j ACCEPT

(5)删除 filter 表中的第 2 条规则。★

iptables -D INPUT 2

(6)清除 filter 表中 INPUT 链的所有规则。★

iptables -t filter -F INPUT

(7)禁止员工访问域名为 http://www.xxxx.org 的网站(域名必须存在,且能被解析,否则会出错)★★★

iptables -A FORWARD -d http://www.xxxx.org -j DROP

iptables -A INPUT -d http://www.xxxx.org -j DROP

(8)禁止员工访问 IP 地址为 212.1.2.3 的网站。★★

iptables -A FORWARD -d 212.1.2.3 -p tcp --port 80 -j DROP

二、firewalld 防火墙

(1)设置 firewalld 防火墙,允许访问 Vsftpd 服务进行文件上传与下载。★★★

firewall-cmd --add-service=ftp --zone=public --permanent

或 firewall-cmd --add-ports=21/tcp,20/tcp --zone=public --permanent

(2)设置 firewalld 防火墙,允许用户使用域名访问 http 和 https 服务。★★★

firewall-cmd --add-service=https --zone=public --permanent

或 firewall-cmd --add-ports=443/tcp,443/udp --zone=public --permanent

(3)设置 firewalld 防火墙,允许用户使用域名访问公司发布的论坛与电商网站。★★★

firewall-cmd --add-service=dns --zone=public --permanent

或 firewall-cmd --add-ports=53/tcp,53/udp --zone=public --permanent

(4)允许内网主机收发邮件

客户端发送邮件时访问邮件服务器 TCP25 端口,接收邮件时访问,可能使用的端口则较多,UDP 协议以及 TCP

协议的端口:110,143,993 以及 995。★★★★

SMTP:邮件发送协议,tcp/25 端口 --permanent

POP3:邮局协议(收邮件)第三版,tcp/110 端口 --permanent

POP3S:邮局加密协议(收邮件)第三版,tcp/995 端口 --permanent

POP2:邮局协议(收邮件)第二版,tcp/109 端口

IMAP:Internet 消息访问协议,和 POP3 一样的功能,tcp/143 端口

IMAPS:Internet 消息加密访问协议,tcp/993 端口

firewall-cmd

–add-ports=25/tcp,110/tcp,995/tcp,143/tcp,993/tcp,–zone=public

–permanent

或 firewall-cmd --add-service={pop3,smtp,imap,pop3s,imaps,} --zone=public --permanent

(5)我们之前发布的电商网站,访问时是通过 8080 端口,请设置 firewalld 防火墙端口转发策略,将 8080 端口禁

用,使用 9099 端口访问电商网站。★★★★★

firewall-cmd --permanent --add-masquerade --permanent

firewall-cmd --add-port=9090/tcp --permanent

firewall-cmd --remove-port=8080/tcp --permanent

firewall-cmd --add-forward-port=port=9099:proto=tcp:toport=8080 --permanent

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值