-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
2024-04-29 14:12:53 [INFO] [src/log_x.rs:42] log is output to /repo/nftables-nat-rust/a/log/nat.log | ||
2024-04-29 14:12:53 [INFO] [src/main.rs:24] kernel ip_forward config enabled! | ||
|
||
2024-04-29 14:12:53 [INFO] [src/main.rs:67] nftables脚本如下: | ||
#!/usr/sbin/nft -f | ||
|
||
add table ip nat | ||
delete table ip nat | ||
add table ip nat | ||
add chain nat PREROUTING { type nat hook prerouting priority -100 ; } | ||
add chain nat POSTROUTING { type nat hook postrouting priority 100 ; } | ||
|
||
# 测试1 | ||
# Single { src_port: 10000, dst_port: 443, dst_domain: "baidu.com", protocol: Tcp } | ||
add rule ip nat PREROUTING tcp dport 10000 counter dnat to 110.242.68.66:443 | ||
#add rule ip nat PREROUTING udp dport 10000 counter dnat to 110.242.68.66:443 | ||
add rule ip nat POSTROUTING ip daddr 110.242.68.66 tcp dport 443 counter snat to 10.0.4.15 | ||
#add rule ip nat POSTROUTING ip daddr 110.242.68.66 udp dport 443 counter snat to 10.0.4.15 | ||
|
||
# 测试2 | ||
# Range { port_start: 1000, port_end: 2000, dst_domain: "baidu.com", protocol: All } | ||
add rule ip nat PREROUTING tcp dport 1000-2000 counter dnat to 110.242.68.66:1000-2000 | ||
add rule ip nat PREROUTING udp dport 1000-2000 counter dnat to 110.242.68.66:1000-2000 | ||
add rule ip nat POSTROUTING ip daddr 110.242.68.66 tcp dport 1000-2000 counter snat to 10.0.4.15 | ||
add rule ip nat POSTROUTING ip daddr 110.242.68.66 udp dport 1000-2000 counter snat to 10.0.4.15 | ||
|
||
#测试3 | ||
# Single { src_port: 2222, dst_port: 22, dst_domain: "localhost", protocol: All } | ||
add rule ip nat PREROUTING tcp dport 2222 redirect to :22 | ||
add rule ip nat PREROUTING udp dport 2222 redirect to :22 | ||
|
||
|
||
2024-04-29 14:12:53 [INFO] [src/main.rs:80] 执行/usr/sbin/nft -f /etc/nftables/nat-diy.nft | ||
执行结果: exit status: 0 | ||
2024-04-29 14:12:53 [INFO] [src/main.rs:90] WAIT:等待配置或目标IP发生改变.... | ||
|
||
2024-04-29 14:13:43 [INFO] [src/log_x.rs:42] log is output to /repo/nftables-nat-rust/a/log/nat.log | ||
2024-04-29 14:13:43 [INFO] [src/main.rs:24] kernel ip_forward config enabled! | ||
|
||
2024-04-29 14:13:43 [INFO] [src/main.rs:67] nftables脚本如下: | ||
#!/usr/sbin/nft -f | ||
|
||
add table ip nat | ||
delete table ip nat | ||
add table ip nat | ||
add chain nat PREROUTING { type nat hook prerouting priority -100 ; } | ||
add chain nat POSTROUTING { type nat hook postrouting priority 100 ; } | ||
|
||
# 测试1 | ||
# Single { src_port: 10000, dst_port: 443, dst_domain: "baidu.com", protocol: Tcp } | ||
add rule ip nat PREROUTING tcp dport 10000 counter dnat to 110.242.68.66:443 | ||
#add rule ip nat PREROUTING udp dport 10000 counter dnat to 110.242.68.66:443 | ||
add rule ip nat POSTROUTING ip daddr 110.242.68.66 tcp dport 443 counter snat to 10.0.4.15 | ||
#add rule ip nat POSTROUTING ip daddr 110.242.68.66 udp dport 443 counter snat to 10.0.4.15 | ||
|
||
# 测试2 | ||
# Range { port_start: 1000, port_end: 2000, dst_domain: "baidu.com", protocol: All } | ||
add rule ip nat PREROUTING tcp dport 1000-2000 counter dnat to 39.156.66.10:1000-2000 | ||
add rule ip nat PREROUTING udp dport 1000-2000 counter dnat to 39.156.66.10:1000-2000 | ||
add rule ip nat POSTROUTING ip daddr 39.156.66.10 tcp dport 1000-2000 counter snat to 10.0.4.15 | ||
add rule ip nat POSTROUTING ip daddr 39.156.66.10 udp dport 1000-2000 counter snat to 10.0.4.15 | ||
|
||
#测试3 | ||
# Single { src_port: 2222, dst_port: 22, dst_domain: "localhost", protocol: All } | ||
add rule ip nat PREROUTING tcp dport 2222 redirect to :22 | ||
add rule ip nat PREROUTING udp dport 2222 redirect to :22 | ||
|
||
|
||
2024-04-29 14:13:43 [INFO] [src/main.rs:80] 执行/usr/sbin/nft -f /etc/nftables/nat-diy.nft | ||
执行结果: exit status: 0 | ||
2024-04-29 14:13:43 [INFO] [src/main.rs:90] WAIT:等待配置或目标IP发生改变.... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters