Linux之防火墙管理

防火墙
一、firewall

firealld域
在这里插入图片描述

1、图形化管理

firewall-config

2、命令行管理

防火墙基本操作


firewall-cmd --state					查看firewall状态
firewall-cmd --get-active-zones			当前正在使用的域
firewall-cmd --get-default-zone			默认的域
firewall-cmd --zone=public --list-all	查看public域的服务
firewall-cmd --get-services				查看可以直接开启的服务
firewall-cmd --list-default-zone=dmz	设置默认域为dmz

firewall-cmd --permanent --zone=internal --add-source=172.25.0.0/24		添加访问来源到域
firewall-cmd --permanent --zone=internal --remove-source=172.25.0.0/24  删除访问源
firewall-cmd --permanent --zone=internal --add-interface=eth0			给internal域添加网卡
firewall-cmd --permanent --zone=internal --remove-interface=eth0		删除internal域网卡
firewall-cmd --permanent --zone=internal --change-interface=eth0		把eth0网卡接到internal域

firewall-cmd --permanent --zone=public --add-service=http	 添加http服务到到public域
firewall-cmd --permanent --zone=public --removce-service=http删除http服务
firewall-cmd --zone=public --list-ports						 列出public的端口
firewall-cmd --permanent --zone=public --add-port=8080/tcp	在public域中添加端口

firewall-cmd --reload					重新载入策略,正在使用的服务不受影响
firewall-cmd --	complete-reload			正在使用的服务会被强制断开
/etc/firewalld							服务配置文件
/etc/firewalld/zones中public.xml.old是public.xml的备份
/lib/firewalld/services					里边是各种服务的数据

特定策略

firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -s 172.25.254.111 -p
tcp --dport 22 -j ACCEPT/REJECT/DROP
					特定172.25.254.111的策略,需要在公共域中去掉此服务
					方能生效
firewall-cmd --direct --add-rule ipv4 filter INPUT 1 ! -s 172.25.254.111 -p
tcp --dport 22 -j ACCEPT/REJECT/DROP
					除了172.25.254.111外的其他主机,需要在公共域中去掉此服务
					方能生效
firewall-cmd --remove-service=ssh			去掉公共域中的ssh 服务
firewall-cmd --derict --get-all-rules		查看特定策略

包头伪装,路由转发功能

默认域设定,可以上外网:
firewall-cmd --add-mansquerade			添加伪装功能
vim /etc/sysctl.conf
	net.ipv4.ip_forward=1
sysctl -p								刷新
sysctl -a | grep ip_forward				查看转发功能是否开启

转发到特定主机的特定端口:
firewall-cmd --add-foward-port=port=22:proto=tcp:toport=22:toaddr=1.1.1.100
二、iptables
1、基础知识
iptable
		-t				指定表的名称
		-n				不做解析				
		-L				列出表中的策略
		-A				增加策略
		-p				网络协议
		--dport			端口
		-s				数据来源
		-j				动作
			ACCEPT			允许
			REJECT			拒绝
			DROP			丢掉
		-N				增加链
		-E				修改链名称
		-X				删除链
		-D				删除指定策略
		-I				插入
		-R				修改策略
		-P				修改默认策略

iptables -t filter -nL			查看filter表的策略
iptables -t nat -nL				查看nat表的策略 
iptables -t mangle				查看mangle的策略
iptables -F						清除策略
service iptables save			保存当前防火墙状态	

2、filter添加策略
iptables -t filter -A INPUT -i  lo -j ACCEPT		   	 回环策略
iptables -t filter -A INPUT -s  172.25.254.111 -j ACCEPT 特定主机策略
iptables -D INPUT 3									删除第三条策略
iptables -R INPUT 2 -s 172.25.254.111 -j REJECT 	修改第二天策略
iptables -I INPUT 2 -s 172.25.254.111 -p tcp --dport=22  -j REJECT 
													插入一条策略
iptables -P INPUT DROP 							修改默认策略
iptables -N westos								添加链
iptables -E westos WESTOS						修改链的名称
iptables -X westos								删除链
3、nat添加策略

访问外网:

iptables -t nat -nL					查看nat表策略
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 22 DNAT --to-dest 1.1.1.100:22
									外网访问内网
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 172.25.254.100
									内网访问外网
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值