Ubuntu共享WiFi(AP)

1 篇文章 0 订阅

第一种方法:比较简单:wifi-hostapd-ap,一个俄罗斯的软件

https://code.google.com/p/wifi-hostapd-ap/downloads/list

第二种方法:Ubuntu共享WiFi(AP)给Android/更新方法二(转)

原文地址:http://weibin.me/538

Android是不支持Ad-hoc模式的WiFi.Windows 7软AP一个还是比较简单的.本文介绍在Ubuntu下实现软AP.(需要你的无线网卡支持AP哈)

使用工具hostapd,dnsmasq.我的环境时Ubuntu10.10;手机Android 2.1;网卡ath5k.有线网络使用静态的IP.

首先,系统是U10.10,安装软件

sudo apt-get install hostapd dnsmasq

为无线添加路由规则

sudo iptables -t nat -A POSTROUTING -s 10.1.1.0/24 -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -s 10.1.1.0/24 -o eth0 -j ACCEPT
sudo iptables -A FORWARD -d 10.1.1.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -i eth0 -j ACCEPT

10.1.1.0/24是我设置的地址段,可以自己改。

若要记录下路由的情况可以加如下语句:

sudo iptables -A INPUT -m conntrack --ctstate NEW -p tcp --dport 80 -j LOG --log-prefix "NEW_HTTP_CONN: "

其中NEW_HTTP_CONN是日记中的标识。

然后把现在iptables的规则写进/etc/iptables.rules

sudo sh -c "iptables-save > /etc/iptables.rules"

配置interface文件,使每次eth0启动时自动写规则

auto eth0
pre-up iptables-restore > /etc/iptables.rules post-down iptables-save > /etc/iptables.rulse

配置hostapd.conf

interface=wlan0
bridge=br0 #方法二中有用到
driver=nl80211
ssid=wbyxu
hw_mode=g
channel=11
dtim_period=1
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=0
auth_algs=3
ieee80211n=0
wpa=3
wpa_passphrase=* #设置密码
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

详细hostapd.conf配置请看http://linuxwireless.org/en/users/Documentation/hostapd.

配置/etc/dnsmasq.conf

interface=wlan0
bind-interfaces #这个是只监听wlan0,没有之会检测所有卡
except-interface=lo
dhcp-range=10.1.1.10,10.1.1.110,6h #设置dhcp地址范
#address=/#/10.1.1.1 #这个会把#(代表所有网址)的dns到10.1.1.1这个地址

dnsmasq与named

一般情况下bind的named会占了53端口,然后dnsmasq会启动不了,所以我用killall named来杀了named再启动dnsmasq。

启动脚本

#! /bin/sh
case "$1" in
    start)
        killall named
        killall hostapd
        ifconfig wlan0 10.1.1.1
        hostapd -B hostapd.conf
        /etc/init.d/dnsmasq restart
        ;;
esac

“-B”后台运行,之后的hostapd.conf需要指名路径.

电脑上完成.

手机上设置WiFi不使用静态IP就可以了.

参考:使用hostapd和dnsmasq实现软AP

以上方法一:使用的是hostapd和dnsmasq实现
更新方法二:使用hostapd和bridge-utils

安装hostapd和bridge-utils

sudo apt-get install hostapd bridge-utils>

这个hostapd的配置和方法一相同。注意里面hostapd.conf里面的第二行就是制订的桥接。

然后就进行桥接

sudo brctl addbr br0 #这个就是hostapd.conf第二行使用的
sudo ifconfig eth0 0.0.0.0 up
sudo ifconfig wlan0 0.0.0.0 up
sudo brctl addif br0 eth0
sudo brctl addif br0 wlan0
sudo ifconfig br0 10.1.21.8 netmask 255.255.255.0 #10.1.21.8是eth0的IP
sudo route add default gw 10.1.21.1

电脑上搞定。手机上设置(例)
静态IP:10.1.21.9
网关:10.1.21.1
掩码:255.255.255.0
DNS:8.8.8.8

呵呵,这个方法比较简单。

Ubuntu 18.04中,如果你的WiFi无法开启或者显示"未发现WiFi适配器",可能有几个原因。首先,你可以通过在终端输入命令"rfkill list all"来查看WiFi的硬件开关状态。如果显示"ideapad_wlan"的Hard blocked为"yes",那么Ubuntu默认关闭了硬件WiFi开关,这可能导致你的WiFi无法开启。\[1\] 解决这个问题的方法是在终端输入命令"sudo modprobe -r ideapad_laptop",然后输入你的登录密码,这样就移除了ideapad无线模块。这样做后,你应该能够在WiFi设置中看到WiFi选项,并能够连接到无线网络。\[3\] 然而,每次启动Ubuntu系统都需要重新进行模块移出是很麻烦的,所以你可以将该命令设置为开机自启动。首先,切换到root用户,在终端输入"su"进入root用户,然后使用命令"sudo gedit /etc/rc.local"来修改文件。请注意,如果你使用的是Ubuntu 18.04,那么在/etc目录下可能没有rc.local这个文件,你需要自行创建一个rc.local文件。\[3\] 通过以上步骤,你应该能够解决Ubuntu 18.04中WiFi无法开启的问题。 #### 引用[.reference_title] - *1* *2* *3* [Ubuntu18.04没有WiFi怎么解决(图文详解)](https://blog.csdn.net/qq_42257666/article/details/118684372)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值