iptables

iptables

三张表

  • filter: 负责过滤数据包,包括的规则链有:input,output和forward
  • nat: 用于网络地址转换(IP、端口),包括的规则链有:prerouting,postrouting 和 output
  • mangle: 主要应用在修改数据包、流量整形、给数据包打标识,默认的规则链有:INPUT,OUTPUT、 forward,POSTROUTING,PREROUTING

优先级:mangle > nat > filter

五条链

  1. input: 匹配目标IP是本机的数据包
  2. output: 出口数据包 , 一般不在此链上做配置
  3. forward: 匹配流经本机的数据包
  4. prerouting: 修改目的地址,用来做 DNAT 。如:把内网中的 80 端口映射到互联网端口
  5. postrouting: 修改源地址,用来做 SNAT。如:局域网共享一个公网IP接入Internet。

docker 相关

1
2
3
4
5
6
root@test-nginx-01:/home/gmadmin# docker network ls
NETWORK ID NAME DRIVER SCOPE
ef620da0c267 bridge bridge local
6dcf2010d701 deploy_default bridge local
2fe1cf2565f2 host host local
37582b0d0afb none null local
1
2
3
4
5
6
7
8
9
10
11
# ip addr
20: br-6dcf2010d701: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:91:16:68:cd brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-6dcf2010d701
valid_lft forever preferred_lft forever
inet6 fe80::42:91ff:fe16:68cd/64 scope link
valid_lft forever preferred_lft forever
96: veth2a5bdb9@if95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-6dcf2010d701 state UP group default
link/ether 42:7b:3f:c7:9d:8a brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::407b:3fff:fec7:9d8a/64 scope link
valid_lft forever preferred_lft forever
1
2
3
4
5
6
7
8
9
10
11
12
# docker inspect 6dcf2010d701
......
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
作者

Ginta

发布于

2023-08-15

更新于

2024-11-11

许可协议

评论