ubuntu使用ap-hotspot来创建WIFI热点

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-get update
$ sudo apt-get install ap-hotspot
$ sudo ap-hotspot configure  //这一步会检查ubuntu的网络和WIFI接口,确定后会提示你配置热点,输入ssid和密码之类的就行了
$ sudo ap-hotspot start

一般的ubuntu以上过程走完手机可以顺利识别并连接上了。

如果不顺利的话看看下面常见问题是否能够帮到你

TX1使用ap-hotspot来创建WIFI热点

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-get update
$ sudo apt-get install ap-hotspot

1提示没有ap-hotspot,不要慌,见问题3

2卡在 Starting Wireless Hotspot,不要慌,见问题2

sudo ./ap-hotspot.sh start

3一切正常就是搜不到wifi

这是因为tx1的网卡模式不对,解决办法

echo 2 > /sys/module/bcmdhd/parameters/op_mode

或者

将下面这一行加到 /etc/modprobe.d/bcmdhd.conf:

options bcmdhd op_mode=2

重新执行,你就会搜到wifi啦

sudo ./ap-hotspot.sh start

4连接wifi提示密码错误,多试几次提示无法加入

这是因为tx1的加解密又问题,编辑/etc/ap-hotspot.conf,不要使用加密模式将以下几行注释掉不需要密码就可以了

#wpa=2
#wpa_passphrase=qwerty0987
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP

再重start就好了,可以连上了

常用命令

start start wireless hotspot//开始使用

stop stop wireless hotspot//停止使用

restart restart wireless hotspot//重启

configure configure hotspot//配置使用

常见问题

1、无法出现Wireless Hotspot active,并一直保持Starting Wireless Hotspot…

先移除hostapd

sudo apt-get remove hostapd

64 位ubuntu使用以下方式

cd /tmp
wget http://old-releases.ubuntu.com/ubuntu/pool/universe/w/wpa/hostapd_1.0-3ubuntu2.1_amd64.deb
sudo dpkg -i hostapd*.deb
sudo apt-mark hold hostapd

“sudo apt-mark hold hostapd” 将防止版本升级到有问题的版本。

再重新安装ap-hotspot

sudo apt-get install ap-hotspot

2、出现Another process is already running

sudo rm /tmp/hotspot.pid

3、ubuntu16、tx1等apt-get安装不了ap-hotspot
不要慌,源码在这里https://github.com/hotice/AP-Hotspot,给予可执行权限

chmod +x ap-hotspot.sh
sudo ./ap-host.sh configure
sudo ./ap-host.sh start

ap-hotspot.sh如下

#!/bin/bash
# Global variables
logfile="/tmp/hostapd.log"
pidfile="/tmp/hotspot.pid"
hotspotconfig="/etc/ap-hotspot.conf"
dnsmasqconfig="/etc/dnsmasq.d/ap-hotspot.rules"
user=$(who | awk '{print $1}' | sed '/^root$/d' | uniq)
WMPID=$(ps -u $user | tail -n 1 | awk '{print $1}')
DBUS=$(egrep -z 'DBUS_SESSION_BUS_ADDRESS|disPLAY' /proc/${WMPID}/environ | sed -r -e 's/(.)DBUS_/\1 DBUS_/' -e 's/(.)disPLAY/\1 disPLAY/')

if command -v service > /dev/null; then
    UPSTART_EXISTS="yes"
else
    UPSTART_EXISTS=
fi

if command -v route > /dev/null; then
    IFCONfig_EXISTS="yes"
else
    IFCONfig_EXISTS=
fi

show_msg() {
echo -e "$@"
}

show_info() {
echo -e "\033[1;34m$@\033[0m"
}

show_warn() {
echo -e "\033[1;33m$@\033[0m"
}

show_err() {
echo -e "\033[1;31m$@\033[0m" 1>&2
}

show_debug() {
while read input; do
    [[ "$debug" == "true" ]] && echo -e "$input"
done
}

show_notify() {
su $user -s /bin/bash -c "${DBUS} notify-send -h int:transient:1 -i \"network-wireless\" \"$@\""
}

check_root() {
# Check if user is root
if [[ ! $(whoami) = "root" ]]; then
    show_err "Please run the script as root"
    exit 1
fi
}

check_supported() {
# Check if the wireless card supports Access Point mode. This script won't work if it doesn't support it
if [[ ! $(iw list 2>&1 | grep -A6 "Supported interface modes" | grep AP$) ]]; then
    show_err "Your wireless card or driver does not support Access Point mode"
    exit 1
fi
}

check_network() {
# Check if Wireless is disabled
if [[ $(iwconfig "$INTERFACE_WLAN" 2>&1 | grep "Tx-Power=off") ]]; then
    show_err "WiFi is disabled,please enable WiFi before running this script"
    exit 1
# Check if Wireless is enabled,but connected to a network
elif [[ ! $(iwconfig "$INTERFACE_WLAN" 2>&1 | grep "ESSID:off/any") && $(iwconfig "$INTERFACE_WLAN" 2>&1 | grep "ESSID:") ]]; then
    show_err "Please disconnect WiFi before proceeding"
    exit 1
fi
}

check_connected() {
# Monitor logfile for connected devices
lines_con="0"
lines_dis="0"
while [[ -f "$logfile" ]]; do
    if [[ "$lines_con" < $(grep -c "AP-STA-CONNECTED" "$logfile") ]]; then
        show_notify "New device connected to Hotspot"
        (( lines_con++ ))
    elif [[ "$lines_dis" < $(grep -c "AP-STA-disCONNECTED" "$logfile") ]]; then
        show_notify "Device disconnected from Hotspot"
        (( lines_dis++ ))
    fi
    sleep 5
done
}

configure() {
# Check root
check_root
# Check supported
check_supported
# Reset config
rm -f "$hotspotconfig"
rm -f "$dnsmasqconfig"
# Detect configuration
show_msg "Detecting configuration..."

#figuring out Default Interent Interface
if command -v route > /dev/null; then
    INTERFACE_NET=$(route | grep -iw "default" | awk '{print $NF}')
elif command -v ip > /dev/null; then
    INTERFACE_NET=$(ip route | grep -iw "default" | awk '{print $5}')
fi

#figuring out Wireless Interface
if command -v iwconfig > /dev/null; then  #Checking presence of iwconfig
    INTERFACE_WLAN=$(iwconfig 2>&1 | grep "^wlan" | sed -e 's/ .*//g' | tail -n 1) #Assuming interface uses old wlan convention
    if [[ ! $INTERFACE_WLAN ]]; then
        INTERFACE_WLAN=$(iwconfig 2>&1 | grep "^wlp" | sed -e 's/ .*//g' | tail -n 1)  #Assuming interface uses new wlp convention
    fi
elif command -v iw > /dev/null; then
    INTERFACE_WLAN=$(iw dev 2>&1 | grep "wlan" | awk '{print $2}' | tail -n 1)
    if [[ ! $INTERFACE_WLAN ]]; then
        INTERFACE_WLAN=$(iwconfig 2>&1 | grep "^wlp" | sed -e 's/ .*//g' | tail -n 1)
    fi
fi

SSID="myhotspot"
WPAPASS="qwerty0987"
# Network interface connected to the Internet
if [[ ! $INTERFACE_NET ]]; then
    show_warn "Failed to detect the network interface connected to the Internet. Please enter your network interface (e.g.- eth1):"
else
    show_msg "Detected $INTERFACE_NET as the network interface connected to the Internet. Press ENTER if this is correct or enter the desired interface below (e.g.- eth0,ppp0 etc.):"
fi
read interface_net
[[ "$interface_net" ]] && INTERFACE_NET="$interface_net"
# WiFi interface
if [[ ! $INTERFACE_WLAN ]]; then
    show_warn "Failed to detect the WiFi interface. Please enter your WiFi interface (e.g.- wlan0):"
else
    show_msg "Detected $INTERFACE_WLAN as your WiFi interface. Press ENTER if this is correct or enter the desired interface (e.g.- wlan1):"
fi
read interface_wlan
[[ "$interface_wlan" ]] && INTERFACE_WLAN="$interface_wlan"
# Hotspot SSID
show_msg "Enter the desired Access Point name or press ENTER to use the default one ($SSID):"
read ssid
[[ "$ssid" ]] && SSID="$ssid"
# WPA Passphrase
show_msg "Enter the desired WPA Passphrase below or press ENTER to use the default one ($WPAPASS):"
read wpapass
[[ "$wpapass" ]] && WPAPASS="$wpapass"
# Write the hostapd config file
cat <<EOF | tee "$hotspotconfig" > /dev/null 2>&1
# WiFi Hotspot
interface=$INTERFACE_WLAN
driver=nl80211
#Access Point
ssid=$SSID
hw_mode=g
# WiFi Channel:
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=$WPAPASS
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF
# Add the required bits to the dnsmasq config file
if [[ ! $(grep "Bind to only one interface" "$dnsmasqconfig" > /dev/null 2>&1) ]]; then
cat <<EOF | tee "$dnsmasqconfig" > /dev/null 2>&1
# Bind to only one interface
bind-interfaces
# Choose interface for binding
interface=$INTERFACE_WLAN
# Specify range of IP addresses for DHCP leases
dhcp-range=192.168.150.2,192.168.150.10,12h
#INTERFACE_NET=$INTERFACE_NET
EOF
chmod +x "$dnsmasqconfig"
fi
}

get_vars() {
# Run Configuration Wizard if config files don't exist
[[ ! -f "$hotspotconfig" || ! -f "$dnsmasqconfig" ]] && configure
# Get $INTERFACE_NET and $INTERFACE_WLAN from the config files
INTERFACE_WLAN=$(grep "interface" "$hotspotconfig" | sed -e 's/interface=//g')
INTERFACE_NET=$(grep "INTERFACE_NET" "$dnsmasqconfig" | sed -e 's/#INTERFACE_NET=//g')
}

start() {
# Check prevIoUs process
if [[ -f "$pidfile" ]]; then
    show_err "Another process is already running"
    exit 1
fi
# Check root
check_root
# Check supported
check_supported
# Get variables
get_vars
# Check network
check_network
# Write the PID to a file
echo "$$" > "$pidfile"
show_info "Starting Wireless Hotspot..."
# Set up the services
if [[ $UPSTART_EXISTS ]]; then
    service hostapd stop 2>&1 | show_debug
    service dnsmasq stop 2>&1 | show_debug
    update-rc.d hostapd disable 2>&1 | show_debug
    update-rc.d dnsmasq disable 2>&1 | show_debug
else
    systemctl stop hostapd 2>&1 | show_debug
    systemctl stop dnsmasq 2>&1 | show_debug
    systemctl disable hostapd 2>&1 | show_debug
    systemctl disable dnsmasq 2>&1 | show_debug
fi
# Configure IP address for WLAN
if [[ $IFCONfig_EXISTS ]]; then
    ifconfig "$INTERFACE_WLAN" 192.168.150.1 2>&1 | show_debug
else #using ip command
    ip addr flush dev "$INTERFACE_WLAN" 2>&1 | show_debug
    ip addr add 192.168.150.1 dev "$INTERFACE_WLAN" 2>&1 | show_debug
fi
# Start DHCP/DNS server
if [[ $UPSTART_EXISTS ]]; then
    service dnsmasq restart 2>&1 | show_debug
else
    systemctl restart dnsmasq 2>&1 | show_debug
fi
# Enable routing
sysctl net.ipv4.ip_forward=1 2>&1 | show_debug
# Enable NAT
iptables -t nat -A POSTROUTING -o "$INTERFACE_NET" -j MASQUERADE 2>&1 | show_debug
# Run access point daemon
if [[ $(hostapd --help 2>&1 | grep "\-f") ]]; then
    rm -f "$logfile"
    touch "$logfile"
    hostapd -B "$hotspotconfig" -f "$logfile"
    while :
    do
        [[ $(grep "Using interface" "$logfile") ]] && show_info "Wireless Hotspot active" && show_notify "Wireless Hotspot active" && break
        sleep 5
    done
    check_connected 2>&1 &
    disown
else    
    hostapd -B "$hotspotconfig" 2>&1 | show_debug
    show_info "Wireless Hotspot active"
fi
}

stop() {
# Check root
check_root
# Get variables
get_vars
# Kill process
show_info "Stopping Wireless Hotspot..."
if [[ -f "$pidfile" ]]; then
    pid=$(cat "$pidfile")
    rm -f "$pidfile"
    [[ $(grep -s "ap-hotspot" "/proc/$pid/cmdline") ]] && kill -9 "$pid"
fi
# Delete log
rm -f "$logfile"
# disable NAT
iptables -D POSTROUTING -t nat -o "$INTERFACE_NET" -j MASQUERADE 2>&1 | show_debug
# disable routing
sysctl net.ipv4.ip_forward=0 2>&1 | show_debug
# Set up the services
service hostapd stop 2>&1 | show_debug
service dnsmasq stop 2>&1 | show_debug
# Restart WiFi and disable newly created mon.WLAN network
if [[ $IFCONfig_EXISTS ]]; then
    if [[ ! -z $(ifconfig | grep "mon.$INTERFACE_WLAN") ]]; then
    # Check if the hotspot is active
        ifconfig "mon.$INTERFACE_WLAN" down
    fi
    ifconfig "$INTERFACE_WLAN" down
    ifconfig "$INTERFACE_WLAN" up
else #Using ip command
    if [[ ! -z $(ip addr | grep "mon.$INTERFACE_WLAN") ]]; then
    # Check if the hotspot is active
        ip link set "mon.$INTERFACE_WLAN" down
    fi
    ip link set "$INTERFACE_WLAN" down
    ip link set "$INTERFACE_WLAN" up
fi
}

restart() {
show_info "Restarting Wireless Hotspot..."
stop
start
}

case "$1" in
    start)
            start;;
    stop)
            stop;;
    restart)
            restart;;
    configure)
            configure;;
    debug)
            debug="true"
            start;;
    *)
            args=( "start" "stop" "restart" "configure" "debug" )
            desc=( "start wireless hotspot" "stop wireless hotspot" "restart wireless hotspot" "configure hotspot" "start with detailed messages" )
            echo -e "Usage:\tap-hotspot [argument]\n"
            for ((i=0; i < ${#args[@]}; i++)); do
                printf "\t%-15s%-s\n" "${args[i]}" "${desc[i]}"
            done
            exit;;
esac

Ubuntu下配置AP热点(TX1配置热点)的更多相关文章

  1. android – 来自adb的’grep’命令的问题

    当我用adb写的时候:我得到错误输出:但如果我将它拆分为两个操作符:它工作正常.如果唯一的方法是将它拆分为两个–首先进入adbshell,然后运行Inquire,有一种方法可以从c#中执行此操作吗?

  2. Android – 连接问题

    我有几个关于Android连接的问题,如果有人的话有任何见解会很棒.1)应用程序想要无线连接时的默认值是多少?如果wlan关闭或没有接入点周围是3g还是gprs?2)设备是否始终ip连接?3)是一个应用程序,例如浏览器只连接到一个IP地址?4)应用程序可以决定打开套接字的连接吗?5)最后,本机应用程序如何处理连接?

  3. android – 当使用LocationManager时,为什么有Wifi但没有连接帮助网络位置?

    可能是您第一次在连接WLAN时激活GPS.SkyHook就是提供这种数据的公司.

  4. 在Android上实施位置追踪

    我是Android开发的新手,想要构建第一个示例应用程序.我的目标是建立一个跟踪应用程序,将我当前的位置发送到远程服务器.我想使用收集的数据来计算我在知名的地方,如家庭或工作中花费了多少个小时.我应该使用哪种方法?GPS不是一个真正的选择,因为最有趣的地方是在室内,我没有GPS连接.我在Android4.0上工作.解决方法如您所说,GPS连接不会在室内工作,但估计您当前的位置非常有用.怎么样?

  5. android – 如何知道应用程序是从Google Play还是Amazon下载?

    有没有办法知道应用程序是从Amazon还是GooglePlay下载?

  6. jQuery中$.grep() 过滤函数 数组过滤

    这篇文章主要介绍了jQuery中$.grep() 过滤函数 数组过滤的相关资料,需非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  7. 浅析jquery数组删除指定元素的方法:grep()

    下面小编就为大家带来一篇浅析jquery数组删除指定元素的方法:grep()。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  8. VS Code开发React-Native及Flutter 开启无线局域网安卓真机调试问题

    这篇文章主要介绍了VS Code开发React-Native,Flutter 开启无线局域网安卓真机调试,需要的朋友可以参考下

  9. Windows中的Grep和Awk表达式错误中的无效字符

    我是grep和awk的新手–使用Windows7.我在运行此脚本时遇到问题:我收到错误:awk:'{printawk:^表达式中的char”’无效我相信它可能与在Windows中使用双引号有关,但我尝试了所有我能想到的组合,但它仍然不起作用.有人可以帮忙吗?谢谢转义命令行项在Windows上总是很痛苦.作为最后的手段,你可以使用gawk-f!

  10. DOS:排除文件类型的目录列表?

    在MS-DOS中,如果我输入dir*.pdf,我将获取目录中的所有PDF文件.有没有办法获得除PDF文件之外的所有内容?我认为findstr有一个/v选项,相当于grep-v(包括所有不包含文本的行.所以我会看:语法可能略有不同,我没有太多需要使用它,我不在我当前的位置运行Windows.使用findstr/?从命令提示符获取详细信息.或者,如果您安装CygWin,您可以使用grep本身:附录:我实际上没有意识到这一点,但显然findstr也支持正则表达式,所以你可以使用:和grep一样.

随机推荐

  1. crontab发送一个月份的电子邮件

    ubuntu14.04邮件服务器:Postfixroot收到来自crontab的十几封电子邮件.这些邮件包含PHP警告.>我已经解决了这些警告的原因.>我已修复每个cronjobs不发送电子邮件(输出发送到>/dev/null2>&1)>我删除了之前的所有电子邮件/var/mail/root/var/spool/mail/root但我仍然每小时收到十几封电子邮件.这些电子邮件来自cronjobs,

  2. 模拟两个ubuntu服务器计算机之间的慢速连接

    我想模拟以下场景:假设我有4台ubuntu服务器机器A,B,C和D.我想在机器A和机器C之间减少20%的网络带宽,在A和B之间减少10%.使用网络模拟/限制工具来做到这一点?

  3. ubuntu-12.04 – 如何在ubuntu 12.04中卸载从源安装的redis?

    我从源代码在Ubuntu12.04上安装了redis-server.但在某些时候它无法完全安装,最后一次makeinstallcmd失败.然后我刚刚通过apt包安装.现在我很困惑哪个安装正在运行哪个conf文件?实际上我想卸载/删除通过源安装的所有内容,只是想安装一个包.转到源代码树并尝试以下命令:如果这不起作用,您可以列出软件自行安装所需的步骤:

  4. ubuntu – “apt-get source”无法找到包但“apt-get install”和“apt-get cache”可以找到它

    我正在尝试下载软件包的源代码,但是当我运行时它无法找到.但是当我运行apt-cache搜索squid3时,它会找到它.它也适用于apt-getinstallsquid3.我使用的是Ubuntu11.04服务器,这是我的/etc/apt/sources.list我已经多次更新了.我尝试了很多不同的debs,并没有发现任何其他地方的错误.这里的问题是你的二进制包(deb)与你的源包(deb-src)不

  5. ubuntu – 有没有办法检测nginx何时完成正常关闭?

    &&touchrestarted),因为即使Nginx没有完成其关闭,touch命令也会立即执行.有没有好办法呢?这样的事情怎么样?因此,pgrep将查找任何Nginx进程,而while循环将让它坐在那里直到它们全部消失.你可以改变一些有用的东西,比如睡1;/etc/init.d/Nginx停止,以便它会休眠一秒钟,然后尝试使用init.d脚本停止Nginx.你也可以在某处放置一个计数器,这样你就可以在需要太长时间时发出轰击信号.

  6. ubuntu – 如何将所有外发电子邮件从postfix重定向到单个地址进行测试

    我正在为基于Web的应用程序设置测试服务器,该应用程序发送一些电子邮件通知.有时候测试是使用真实的客户数据进行的,因此我需要保证服务器在我们测试时无法向真实客户发送电子邮件.我想要的是配置postfix,以便它接收任何外发电子邮件并将其重定向到一个电子邮件地址,而不是传递到真正的目的地.我正在运行ubuntu服务器9.10.先感谢您设置本地用户以接收所有被困邮件:你需要在main.cf中添加:然后

  7. ubuntu – vagrant无法连接到虚拟框

    当我使用基本的Vagrantfile,只配置了两条线:我看到我的虚拟框打开,但是我的流氓日志多次显示此行直到超时:然后,超时后的一段时间,虚拟框框终于要求我登录,但是太久了!所以我用流氓/流氓记录.然后在我的物理机器上,如果我“流氓ssh”.没有事情发生,直到:怎么了?

  8. ubuntu – Nginx – 转发HTTP AUTH – 用户?

    我和Nginx和Jenkins有些麻烦.我尝试使用Nginx作为Jenkins实例的反向代理,使用HTTP基本身份验证.它到目前为止工作,但我不知道如何传递带有AUTH用户名的标头?}尝试将此指令添加到您的位置块

  9. Debian / Ubuntu – 删除后如何恢复/ var / cache / apt结构?

    我在ubuntu服务器上的空间不足,所以我做了这个命令以节省空间但是现在在尝试使用apt时,我会收到以下错误:等等显然我删除了一些目录结构.有没有办法做apt-getrebuild-var-tree或类似的?

  10. 检查ubuntu上安装的rubygems版本?

    如何查看我的ubuntu盒子上安装的rubygems版本?只是一个想法,列出已安装的软件包和grep为ruby或宝石或其他:)dpkg–get-selections

返回
顶部