This commit is contained in:
2026-03-05 23:30:12 +08:00
parent e6cbbd27d4
commit c33559fcf8
3 changed files with 39 additions and 2 deletions

17
docs/src/pages/ip-step.md Normal file
View File

@@ -0,0 +1,17 @@
# 1. 清理重复规则
iptables -t nat -F PREROUTING
iptables -t nat -F POSTROUTING
# 2. 重新添加正确规则
# DNAT - 目的地址转换
iptables -t nat -A PREROUTING -i eth1 -p udp --dport 5060 -j DNAT --to-destination 192.168.9.4:5060
# SNAT - 源地址转换
iptables -t nat -A POSTROUTING -o eth0 -p udp --dport 5060 -j SNAT --to-source 192.168.9.57
# 3. 开启 IP 转发
echo 1 > /proc/sys/net/ipv4/ip_forward
# 4. 添加 FORWARD 规则(重要!)
iptables -A FORWARD -i eth1 -o eth0 -p udp --dport 5060 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -p udp --sport 5060 -j ACCEPT

View File

@@ -8,7 +8,15 @@ layout: ../layouts/MDXPost.astro
## 提示词
有一个andorid有两个网口一个网口是A局域网一个是B局域网。A 的地址是 192.168.3.3,名字叫 A地址B 地址是 192.168.9.57 名字叫 B 地址, 如何实现A局域网下的有一个设备能直接访问B局域网的 一个设备比如192.168.9.4这是 C 设备他是是B的局域网内的. 要从192.168.3.33 的 D 设备D 设备是 MAC 设备,是 A 局域网的。A 局域网的 D需要访问到 B 局域网中的 192.168.9.4的设备 C如何配置
有一个andorid有两个网口一个网口是A局域网一个是B局域网。
A 的地址是 192.168.3.3,名字叫 A地址
B 地址是 192.168.9.57 名字叫 B 地址,
如何实现A局域网下的有一个设备能直接访问B局域网的一个设备192.168.9.4这是 C 设备他是是B的局域网内的.
要从192.168.3.33 的 D 设备D 设备是 MAC 设备,是 A 局域网的。
A 局域网的 D需要访问到 B 局域网中的 192.168.9.4的设备 C如何配置D 发送 UDP 包到 C 设备
## 开启 iptables

View File

@@ -1,3 +1,12 @@
查看iptables规则
```bash
iptables -L -n -v
# 查看nat表的PREROUTING链
iptables -t nat -L PREROUTING -n --line-numbers
# 查看nat表的POSTROUTING链
iptables -t nat -L POSTROUTING -n --line-numbers
```
# 1. 允许转发从eth1到eth0的SIP数据包目的192.168.9.4:5060
iptables -A FORWARD -i eth1 -o eth0 -p udp --dport 5060 -d 192.168.9.4 -j ACCEPT
@@ -9,3 +18,6 @@ iptables -t nat -A PREROUTING -i eth1 -p udp --dport 5060 -j DNAT --to-destinati
# 4. SNAT修改转发包的源地址为设备eth0的IP192.168.9.57确保192.168.9.4的响应能回传给设备
iptables -t nat -A POSTROUTING -o eth0 -p udp --dport 5060 -d 192.168.9.4 -j SNAT --to-source 192.168.9.57
# 5. 保存iptables规则
iptables-save > /etc/iptables/rules.v4