git clone ssh://git@gogs.magong.site:10022/mrh/Natter-v2.git
BIND_IP = 192.168.2.32 # 绑定的ip地址,需要将本机哪个网卡的地址暴露在公网上,尝试进行打洞
FORWARD_IP = 192.168.2.32 # 转发的ip地址,公网访问我时,将流量转发到局域网哪个地址上,用于查看访问是否成功
python natter.py -t $FORWARD_IP -p 80 -i $BIND_IP -b 9820
# python natter.py -t 192.168.2.32 -p 80 -i 192.168.2.32 -b 9820
设置 DMZ ,可以将任意端口暴露在公网上,例如设置 192.168.2.31 ,说明该地址的防火墙是一个 Easy Nat ,轻松实现打洞
也可以设置端口转发,在某些光猫也叫 虚拟主机。例如我当前设置:
名称:随便;
# ❗❗协议一定要有两种
协议: UDP AND TCP
广域网主机起始ip地址,广域网主机结束ip地址:不填;
广域网连接,选择路由模式的连接,也就是当前电脑使用的联网模式;
广域网起始端口,广域网结束端口,这个如果只有1个端口如80,就2个都填写80;
启用mac映射,这个不勾也是可以的;
虚拟主机ip地址,局域网内部IP地址,看你自己的网路连接的ip地址就可以了;
虚拟主机起始端口,虚拟主机结束端口,这个如果只有1个端口如80,就2个多填写80;
Expose your port behind full-cone NAT to the Internet.
python3 natter.py
Or, using Docker:
docker run --net=host nattertool/natter
2023-11-01 01:00:08 [I] Natter v2.0.0-rc1
2023-11-01 01:00:08 [I] Tips: Use `--help` to see help messages
2023-11-01 01:00:12 [I]
2023-11-01 01:00:12 [I] tcp://192.168.1.100:13483 <--Natter--> tcp://203.0.113.10:14500
2023-11-01 01:00:12 [I]
2023-11-01 01:00:12 [I] Test mode in on.
2023-11-01 01:00:12 [I] Please check [ http://203.0.113.10:14500 ]
2023-11-01 01:00:12 [I]
2023-11-01 01:00:12 [I] LAN > 192.168.1.100:13483 [ OPEN ]
2023-11-01 01:00:12 [I] LAN > 192.168.1.100:13483 [ OPEN ]
2023-11-01 01:00:12 [I] LAN > 203.0.113.10:14500 [ OPEN ]
2023-11-01 01:00:13 [I] WAN > 203.0.113.10:14500 [ OPEN ]
2023-11-01 01:00:13 [I]
In the example above, 203.0.113.10 is your public IP address outside the full-cone NAT. Natter opened TCP port 203.0.113.10:14500 for testing.
Visit http://203.0.113.10:14500 outside your LAN, you will see the web page:
It works!
--------
Natter
usage: natter.py [--version] [--help] [-v] [-q] [-u] [-k <interval>]
[-s <address>] [-h <address>] [-e <path>] [-i <interface>]
[-b <port>] [-m <method>] [-t <address>] [-p <port>] [-r]
Expose your port behind full-cone NAT to the Internet.
options:
--version, -V show the version of Natter and exit
--help show this help message and exit
-v verbose mode, printing debug messages
-q exit when mapped address is changed
-u UDP mode
-k <interval> seconds between each keep-alive
-s <address> hostname or address to STUN server
-h <address> hostname or address to keep-alive server
-e <path> script path for notifying mapped address
bind options:
-i <interface> network interface name or IP to bind
-b <port> port number to bind
forward options:
-m <method> forward method, common values are 'iptables', 'nftables',
'socat', 'gost' and 'socket'
-t <address> IP address of forward target
-p <port> port number of forward target
-r keep retrying until the port of forward target is open
Read natter-docker for details.
Expose local port 80 to the Internet, using built-in forward method:
python3 natter.py -p 80
Expose local port 80 to the Internet, using iptables kernel forward method (requires root permission):
sudo python3 natter.py -m iptables -p 80
GNU General Public License v3.0