ioiioi
V2EX  ›  问与答

如何查看iptables中的nat session?

  •  
  •   ioiioi · Dec 19, 2013 · 5882 views
    This topic created in 4572 days ago, the information mentioned may be changed or developed.
    如果说我有个内网段为192.168.1.0/24需要映射成1.1.1.1出局。
    如何查看192.168.1.2:6223 <-> 8.8.8.8:53的这个session?

    192.168.1.2:6223在linux的netfilter会映射成什么样呢?
    会不会源端口不变,直接改掉源地址?
    2 replies    1970-01-01 08:00:00 +08:00
    fqrouter2
        1
    fqrouter2  
       Dec 20, 2013 via Android
    conntrack目录
    ioiioi
        2
    ioiioi  
    OP
       Dec 20, 2013
    嗯,如果能更详细点就好了,今天有空做了点研究。

    实际案例:

    在RB493G中使用ssh连接221.x.x.190

    root@RB493G:/etc/config# conntrack -L -d 221.x.x.190
    tcp 6 3597 ESTABLISHED src=192.168.44.3 dst=221.x.x.190 sport=45442 dport=22 packets=523 bytes=31905 src=221.x.x.190 dst=183.254.47.33 sport=22 dport=45442 packets=514 bytes=101605 [ASSURED] mark=0 use=1
    conntrack v1.0.0 (conntrack-tools): 1 flow entries have been shown.

    root@RB493G:/etc/config# netstat-nat -n -d 221.x.x.190
    Proto NATed Address Destination Address State
    tcp 192.168.44.3:45442 221.x.x.190:22 ESTABLISHED

    root@openbsd-2/etc:# netstat -an | grep 22
    tcp 0 84 221.x.x.190.22 183.254.47.33.45442 ESTABLISHED

    由此看出,RB493G优先使用了45442这个源端口向221.192.254.190:22发出请求,当45442被其它connection占用后,才另行找新的源端口。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1668 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 6b34f497 · 29ms · UTC 16:21 · PVG 00:21 · LAX 09:21 · JFK 12:21
    ♥ Do have faith in what you're doing.