NAT 的几种应用场景

1、让同一设备内的其它网口上网

下图的功能,其实就是一个4G路由器,可以有线上网,也可以无线上网。

可以通过NAT规则轻松实现。

 比如,LTE模块拨号成功,网口名称为  lte0

针对wifi ap :

service isc-dhcp-server stop
sed "/INTERFACES=/c\INTERFACES=wlan0" -i /etc/default/isc-dhcp-server
sed "/interface=/c\interface=wlan0" -i /etc/hostapd/hostapd.conf

hostapd -B /etc/hostapd/hostapd.conf
sleep 1

ifconfig wlan0 10.5.5.1/24
service isc-dhcp-server restart

echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o lte0 -j MASQUERADE

iptable执行Masquerade,把源IP更改为宿主机网卡的IP,然后向外网服务器发送请求。

原理大概如下:

 

 

$ cat /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server initscript
# sourced by /etc/init.d/isc-dhcp-server
# installed at /etc/default/isc-dhcp-server by the maintainer scripts

#
# This is a POSIX shell fragment
#

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPD_CONF=/etc/dhcp/dhcpd.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPD_PID=/var/run/dhcpd.pid

# Additional options to start dhcpd with.
#       Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="wlp1s0"



$ cat /etc/hostapd/hostapd.conf 
interface=wlP2p1s0
driver=nl80211
ssid=test
channel=6
hw_mode=g
auth_algs=1
wpa=3
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值