问题原文
原帖链接 · obeattie · CC BY-SA 3.0
If I set up a Linux iptables MASQUERADE rule for traffic going out of a specific interface, but that interface has multiple IP addresses, how does the source IP get chosen?
As an example, let's suppose I add a rule like:
$ iptables -t nat -A POSTROUTING -o eno1 -j MASQUERADE
…and that interface looks like:
$ ip addr show dev eno1
1: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 94:18:82:35:a2:c1 brd ff:ff:ff:ff:ff:ff
inet 10.136.122.97/24 scope global eno1
valid_lft forever preferred_lft forever
inet 10.136.122.98/24 scope global eno1
valid_lft forever preferred_lft forever
社区高分解答
原帖链接 · Anton Danilov · CC BY-SA 4.0
The masquerade selects an address in the same way as the source address is selected in routing.
So, you can use ip route get <dst> command to determine the address what will be used as the source address after masquerading.
If you interested in more details, you can look into the source code.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
