设备情况:PC或者树莓派,两张以太网卡,一张主板自带,一张USB网卡
Equipment: PC or berries, two Ethernet cards, one plate, one USB net card
网络设置:网卡eth0连接外网,网卡eth1连接内网
Network settings: Netcaeth0 connected to the extranet and Netcaeth1 connected to the intranet
目的:让eth0的网络共享给eth1,使eth1连接的内网环境的其他设备可以实现连接外网
Purpose: To share eth0's network to eth1, so that other devices of the eth1-connected inner network environment can connect to the outer network
IP设置:eth0无需设置,使用原本的设置即可(DHCP或者静态IP),eth1设置IP:192.168.0.1,子网掩码:255.255.255.0
IP Settings: Eth0 does not need to be set, use the original settings (DHCP or static IP), Eth1 sets IP: 192.168.0.1, subnet mask: 255.255.255.0
在UBUNTU中使用命令行修改?sudo vi /etc/network/interface,如果eth0网卡可以连接外网,这里就不去修改eth0的信息,如果不能连接外网,需先解决连接外网问题后再修改该文件。
修改eth1的IP信息:
Modify IP information for eth1:
auto eth1
iface eth1 inet static
address 192.168.0.1
netmask 255.255.255.0
在树莓派中使用命令行修改 sudo vi /etc/dhcpcd.conf
Use command lines to modify sudo vi/etc/dhcpcd.conf in raspberry pies
添加或者修改eth1的IP信息:
Add or modify IP information for eth1:
interface eth1
static ip_address=192.168.0.1/24
方法一:使用命令?sudo echo 1 >/proc/sys/net/ipv4/ip_forward,该方法只能生效一次,重启后失效
Method I: Use of an order? sudo bycho 1 & gt;/proc/sys/net/ipv4/ip_forward, which can only be effective once, and will expire after restart
方法二:修改sysctl.conf文件 sudo vi /etc/sysctl.conf,将net.ipv4.ip_forward=1前面的#注释去掉,然后执行sudo sysctl -p
Method II: Modify the syscl.conf document sudo vi/etc/syscl.conf, remove the # comments from net.ipv4.ip_forward=1, and then execute syscl-p
使用命令:
Use command:
iptables -F
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
重启后同样会失效,所以需要把这四行命令添加到启动项文件rc.local中,(注:添加在exit 0之前)
The restart will also fail, so the four-line command needs to be added to the start-up file rc.local (note: added before exit0)
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论