首页 > 系统相关 >iptables

iptables

时间:2022-10-04 23:11:52浏览次数:37  
标签:iptables -- ip 192.168 filter dport

ACL

拒绝进入防火墙的所有ICMP数据凶包

iptables -t filter -I INPUT -p icmp -j REJECT

拒绝转发来自192.168.1.10主机的数据

iptables -t filter -A FORWARD -s 192.168.1.10 -j REJECT

丢弃从外网接口(eth1)进入防火墙,源地址为私网地址的数据包

iptables -t filter -A INPUT -i eth1 -s 192.168.0.0/16 -j DROP

只允许管理员从202.13.0.0/16网段使用ssh远程登录防火墙主机

iptabels -t filter -A INPUT -p tcp --dport 22 -s 202.13.0.0/16 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 22 -j DROP

允许转发来自192.168.0.0/24局域网段的DNS解析请求数据包

iptables -t filter -A FORWARD -s 192.168.0.0/24 -p udp --dport 53 -j ACCEPT
iptables -t filter -A FORWARD -d 192.168.0.0/24 -p udp --sport 53 -j ACCEPT

禁止转发来自MAC地址为00:0c:29:27:55:3f主机的数据包

iptables -t filter -A INPUT -m mac --mac-source 00:0c:29:27:55:3f -j DROP

NAT

SNAT(源地址转换)

作用

修改数据包的源IP地

临时打开端口转发

echo 1 > /proc/sys/net/ipv4/ip_forward
# sysctl -w net.ipv4.ip forward=1

永久打开端口转发

vim /etc/sysctl.conf
net.ipv4.ip_forward=1
sysctl -P

转换为固定公网IP地址

iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens33 -j SNAT --to 10.0.0.1
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens33 -j SNAT --to-source 10.0.0.1-10.0.0.10

动态ip地址

iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens33 -j MASQUERADE

DNAT (目标地址转换)

作用

修改数据包的目标IP地址

发布内网的Web服务

# 把从ens33进来的要访问web服务的数据包目的地址转换为 192.168.100.102
iptables -t nat -A PREROUTING -i ens33 -d 12.0.0.1 -p tcp--dport 80 -j DNAT --to 192.168.100.102

修改目标端口

# 发布局域网内部的OpenSSH服务器,外网主机需要使用250端口进行连接
iptables -t nat -A PREROUTING -i ens33 -d 12.0.0.1 -p tcp--dport 250 -j DNAT --to 192.168.100.102:22

RAW

跳过链接跟综和NAT

iptables -t raw -A PREROUTING -d 192.168.56.102 -j NOTRACK

MANGLE

打标记

iptables -t manage -A PREROUTING -i eth0 -p tcp --dport 80:443 -j MARK --set-mark 1
iptables -t manage -A PREROUTING -i eth0 -p tcp --dport 20:21 -j MARK --set-mark 2

制定两个路由表10,20,通过两种标签做,分别做静态路由

ip route add default via 202.106.1.1 dev eth1 table 10
ip route add default via 211.108.1.1 dev eth2 table 20

ip rule add from all fwmark 1 table 10
ip rule add from all fwmark 2 table 20

标签:iptables,--,ip,192.168,filter,dport
From: https://www.cnblogs.com/shiguoliang/p/16565253.html

相关文章

  • centos----------防火墙firewalld和iptables
    1、CentOS7默认的防火墙不是iptables,而是firewalle。关闭防火墙systemctlstopfirewalld启用防火墙systemctlstartfirewalld禁用防火墙systemctlmask......
  • iptables 常用命令解析
    查看当前iptables规则:iptables-n-L--line-numbers该命令会以列表的形式显示出当前使用的iptables规则,并不做解析,每一条规则前面的编号可以用来做为其它操作,例如后面的......
  • centos7 中iptables、firewalld 和 netfilter 的关系
    centos7系统使用firewalld服务替代了iptables服务,但是依然可以使用iptables来管理内核的netfilter但其实iptables服务和firewalld服务都不是真正的防火墙,只是用来定......
  • linux iptables
    目录linuxiptablesNetfilter模块四表五链四表五链四表五链之间的关系iptables语法参数iptables语法格式iptables常用参数常用实例删除已有规则设置链的默认策略阻止指......
  • iptables中limit 和 limit-burst 说明
    Limitmatch    这个匹配操作必须由-mlimit明确指定才能使用。有了他的帮助,就能对指定的规则的日志数量加以限制,以免你被信息的洪流淹没哦。比如,你能事先设定一个限定......
  • Iptables - 基础应用
     iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分。-t<表>:指定要操纵的表;-A:向规则链中添加条目;-D:从规则链中删除条目;-I:向规则链中插入条目;-R:......
  • 详解iptables
    iptables4表5链1、5链2、4表iptables用法示例1、只允许172.16.0.0网段的机器访问本机的443端口#-A是加到末尾,这种情况万一前面的规则拒绝了,这个规则就......
  • iptables 控制docker端口开放范围
    对于类似dockerrun-d-p80:80shaowenchen/demo-whoami运行的服务,需要在DOCKER-USER链中添加规则。Docker会将iptables规则添加到DOCKER链中,如果需要在Docke......
  • (转)CentOS6 iptables 记录指定IP的网络访问日志
     修改文件/etc/rsyslog.conf加入#DIYiptablesLogsave#kern.warning/var/log/iptables/iptables.logkern.debug/var/log/iptables/iptables.log修改文件/etc/......
  • 通过iptables转发到TDSQL实现外网访问云数据库
    腾讯云有些TDSQL,如pgsql版的不能通过外网访问。此时提供2种方案,一种是nginx转发,一种是iptables。这看起来都需要额外的服务器成本,没办法。这里我们使用iptables,因为最方便......