如何将我的 CentOS 笔记本电脑变成无线信号中继器?

如何将我的 CentOS 笔记本电脑变成无线信号中继器?

所以,我有一台装有 CentOS 6.9(i686 arch)的笔记本电脑,我需要通过 Wi-Fi 适配器接收互联网信号并将其转发到以太网电缆,我该怎么做?有什么办法吗?

答案1

Wlan0 可能连接到专用 DSL / ADSL / WAN / 电缆路由器。
但您可能希望将其设置为静态 IP。


本答案使用这些地址作为示例。

  • WAN ISP 子网 =192.168.1.0/24
  • WAN ISP 路由器 =192.168.1.1/24

192.168.1.0WLAN0 接口在子网中静态分配了一个号码

10.10.10.0/24子网中静态分配编号的以太网接口
(Eth0 - 10.10.10.254/24)


步骤1:启用数据包转发

以root用户登录。打开/etc/sysctl.conf文件

vi /etc/sysctl.conf

添加以下行以启用数据包转发:

net.ipv4.conf.default.forwarding=1

节省关闭文件。

重启网络:

service network restart

步骤 #2:启用 IP 伪装

您需要设置网络地址转换 (NAT) 或网络伪装。简而言之,IP 伪装/NA​​T 用于共享互联网连接。

共享互联网连接

要通过以下方式共享网络连接eth0,请在命令提示符下输入以下规则

service iptables stop
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
service iptables save
service iptables restart

打开 Windows / Mac / Linux 计算机网络 GUI 工具并将默认网关指向我们将要共享的接口 IP 地址 (10.10.10.254/24)。您还需要设置 DNS IP,例如208.67.222.2228.8.8.8等。

您现在应该能够 ping 或浏览互联网:

ping 202.54.1.20
ping google.com

发现自动化 shell 脚本这里设置基本的Linux网络共享:

#!/bin/bash
# Created by nixCraft - www.cyberciti.biz
IPT="/sbin/iptables"
MOD="/sbin/modprobe"

# set wan interface such as eth1 or ppp0
SHARE_IF="eth0"

# clean old fw
echo "Clearing old firewall rules..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT

# Get some kernel modules
echo "Loading kernel modules..."
$MOD ip_tables
$MOD iptable_filter
$MOD iptable_nat
$MOD ip_conntrack
$MOD ipt_MASQUERADE
$MOD ip_nat_ftp
$MOD ip_nat_irc
$MOD ip_conntrack_ftp
$MOD ip_conntrack_irc

# Clean old rules if any, rhel specific but above will take care of everything
# service iptables stop

# unlimited traffic via loopback device
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT

echo "Setting ${SHARE_IF} as router interface..."
$IPT --table nat --append POSTROUTING --out-interface ${SHARE_IF} -j MASQUERADE

# Start other custom rules
#$IPT 
# End other custom rules

echo "*** Instructions on TCP/IP On The Windows / Mac / Linux Masqueraded Client ***"
echo "1. Login to your other LAN desktop computers"
echo "2. Open network configuration GUI tool such. Under Windows XP - Click Start, click Control Panel, click Network and Internet Connections, and then click Network Connections"
echo "3. Set DNS (NS1 and NS2) to 208.67.222.222 and 208.67.220.220"
echo "4. Select the 'Gateway' tab in the TCP/IP properties dialog."
echo "5. Enter $(ifconfig ${SHARE_IF} | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}') as the default gateway."

参考:

相关内容