您尚未登录。

楼主 # 2022-09-18 00:59:24

XIVN1987
会员
注册时间: 2019-08-30
已发帖子: 231
积分: 289.5

R5S 运行 Debian 配置成软路由,NAT 不工作,,求教怎么改。。

/etc/network/interfaces 配置如下:

auto eth0
iface eth0 inet dhcp

auto wifi0
iface wifi0 inet dhcp
    wpa-essid xxxxxxxxxx
    wpa-psk xxxxxxxxxx

auto br-lan
iface br-lan inet static
    address 192.168.2.1
    network 192.168.2.0
    netmask 255.255.255.0
    broadcast 192.168.2.255
    bridge-ports eth1 eth2

R5S 通过 USB WiFi 连接主路由,,配置 dhcpd 监听网桥 br-lan,,笔记本通过网线连接 R5S LAN 口
这样配置后,,R5S 通过 WiFi 联通互联网成功,,笔记本分配局域网地址成功,,

接下来只需要配置好 NAT,,笔记本应该就能通过 R5S 联通互联网了,,根据网上搜到的资料,NAT 配置代码如下:

EXTIF="wifi0"
INTIF="br-lan"

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat --flush
iptables -t filter --flush

iptables -t nat -A POSTROUTING -o "$EXTIF" -j MASQUERADE

# Allow traffic from internal to external
iptables -A FORWARD -i "$INTIF" -o "$EXTIF" -j ACCEPT
# Allow returning traffic from external to internal
iptables -A FORWARD -i "$EXTIF" -o "$INTIF" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

但我执行上述代码后,,笔记本以太网显示“无 Internet”,,笔记本上 ping 192.168.2.1 能 ping 通,,但 ping 192.168.18.1(主路由器IP)ping 不通,,请教我哪里配置有问题?该怎么解决??多谢大侠指教。。

离线

楼主 #1 2022-09-18 11:24:35

XIVN1987
会员
注册时间: 2019-08-30
已发帖子: 231
积分: 289.5

Re: R5S 运行 Debian 配置成软路由,NAT 不工作,,求教怎么改。。

执行 ipconfig /all 打印如下,,看起来设置都正常的,,没发现什么问题

无线局域网适配器 WLAN 3:

   连接特定的 DNS 后缀 . . . . . . . : lan
   描述. . . . . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX200 160MHz
   物理地址. . . . . . . . . . . . . : 64-BC-58-05-05-9B
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是
   IPv6 地址 . . . . . . . . . . . . : fd88:88b7:3d35:0:6584:d263:af42:295e(首选)
   临时 IPv6 地址. . . . . . . . . . : fd88:88b7:3d35:0:a5a8:3e7b:b0f4:5beb(首选)
   本地链接 IPv6 地址. . . . . . . . : fe80::6584:d263:af42:295e%11(首选)
   IPv4 地址 . . . . . . . . . . . . : 192.168.18.107(首选)
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   获得租约的时间  . . . . . . . . . : 2022年9月18日 6:28:28
   租约过期的时间  . . . . . . . . . : 2022年9月18日 23:16:11
   默认网关. . . . . . . . . . . . . : 192.168.18.1
   DHCP 服务器 . . . . . . . . . . . : 192.168.18.1
   DHCPv6 IAID . . . . . . . . . . . : 577027160
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-28-4B-DA-A9-80-30-49-2D-36-C5
   DNS 服务器  . . . . . . . . . . . : 192.168.18.1
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用
   连接特定的 DNS 后缀搜索列表:
                                       lan

以太网适配器 以太网 3:

   连接特定的 DNS 后缀 . . . . . . . : example.org
   描述. . . . . . . . . . . . . . . : ASIX AX88179A USB 3.2 Gen1 to Gigabit Ethernet Adapter
   物理地址. . . . . . . . . . . . . : F8-E4-3B-5B-2C-46
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是
   本地链接 IPv6 地址. . . . . . . . : fe80::f474:2cd3:a8c:c01e%19(首选)
   IPv4 地址 . . . . . . . . . . . . : 192.168.2.10(首选)
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   获得租约的时间  . . . . . . . . . : 2022年9月18日 11:12:34
   租约过期的时间  . . . . . . . . . : 2022年9月18日 11:27:27
   默认网关. . . . . . . . . . . . . : 192.168.2.1
   DHCP 服务器 . . . . . . . . . . . : 192.168.2.1
   DHCPv6 IAID . . . . . . . . . . . : 922281019
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-28-4B-DA-A9-80-30-49-2D-36-C5
   DNS 服务器  . . . . . . . . . . . : 192.168.2.1
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用

ip、gateway、dns 服务器都设置了,,可笔记本只连 r5s lan 口的时候就是无法 ping 通外网,,不知道还有哪里设置不对。。

离线

楼主 #2 2022-09-18 15:24:40

XIVN1987
会员
注册时间: 2019-08-30
已发帖子: 231
积分: 289.5

Re: R5S 运行 Debian 配置成软路由,NAT 不工作,,求教怎么改。。

补充,,iptable 规则如下:

root@Armbian:~# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  br-lan wifi0   0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  wifi0  br-lan  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

root@Armbian:~# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  all  --  *      wifi0   0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

最近编辑记录 XIVN1987 (2022-09-18 15:24:56)

离线

楼主 #3 2022-09-18 21:49:01

XIVN1987
会员
注册时间: 2019-08-30
已发帖子: 231
积分: 289.5

Re: R5S 运行 Debian 配置成软路由,NAT 不工作,,求教怎么改。。

问题解决了,,解决方法是在 /etc/dhcp/dhcpd.conf 中下面的 subnet 配置中添加 routers 和 domain-name-servers 设置

subnet 192.168.2.0 netmask 255.255.255.0 {
 range 192.168.2.10 192.168.2.250;
 option routers 192.168.2.1;
 option domain-name-servers 8.8.8.8;
}

routers 选项用来设置接入设备的默认网关,这样接入设备就能 ping 通外网 IP 了。。
domain-name-servers 选项用来设置接入设备的域名解析服务器,之前由于笔记本通过 WiFi 获取的 DNS 是主路由的 IP,因此我也将上面的 DNS 设置成了 br-lan 的 IP,,结果发现不能 ping 通域名,,改成 8.8.8.8 就可以了。。

离线

#4 2022-10-13 17:09:08

taotieren
会员
注册时间: 2020-05-19
已发帖子: 108
积分: 148

Re: R5S 运行 Debian 配置成软路由,NAT 不工作,,求教怎么改。。

R5S 配置如何呢?在那能卖呢?能兼容那些 Linux 发行版呢?

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn