0416笔记

防火墙 selinux

临时关闭
setenforce 0
永久关闭
vi /etc/selinux/config
关闭firewalled 开启netfilter方法
systemctl stop firewalled
systemctl disable firewalled
yum install -y iptables-services
systemctl enable iptables
system start iptables

netfilter五表五链

filter用于过滤 有input LOCALHOST output
nat 用于网络地址转换 有 prerouting FORWARD postrouting
在这里插入图片描述

iptables 语法

iptables -nvL 查看
iptables-F 清空
service iptables save 永久保存当前规则到配置文件
service iptables restart 重启规则
iptables配置文件路径 /etc/sysconfig/iptables
iptable -t filter 默认是对filter表操作,-t nat 对网络转换表操作 t:table 指定表
iptables -Z 清零
iptables-D 删除规则
iptables -nvL --numbers 加上序号查看
iptables 针对一个网段
iptables -I INPUT -m iprange --src-range 61.4.176.0-61.4.191.255 -j DROP
iptables-P OUTPUT DROP 关闭所有input 关闭后ssh就连不上了
iptables -I -INPUT -p icmp --icmp-type 8 -j DROP 可以ping出去,别人ping不到自己。

nat表应用

1.打开路由转发 echo"1">/proc/sys/net/ipv4/ip_forward 该文件默认为0,表示没有开启内核转发。所以要把该文件改为1.
2.设置转发规则 iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth33 -j MASQUERADE
3.设置B主机网关为192.168.100.1 ,用B主机ping A的外网网卡ip,看能否ping通。

猜你喜欢

转载自blog.csdn.net/weixin_42405611/article/details/89350995