微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ubuntu下配置AP热点(TX1配置热点)

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、安装SSH和配置SSH无密码登录四、安装Java环境1. 安装JDK2. 配置JDK环境3. 检验安装五、安装单机Hadoop1. 下载安装Hadoop2. 运行示例总结前言本文安装的 Hadoop 及 Java 环境基于林子雨老师的《大数据技术原理与应用(第3版)》中所要求,其中Java 版本为1.8.0_301,Hadoop 版本为3.3.1,其他版本的安装请参考其他博客。..
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html  运行django出现错误信息:[2016-02-16 14:33:24,476 pyinotify ERROR] add_watch: cannot watch /usr/local/lib/python2.7/dist-packages/django/contrib/sessio...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失了,如下:别着急,以下教你如何找回之前的虚拟机:1、点击控制,然后选择注册,找到虚拟机的安装目录,比如:C:UserstxVirtualBox VMs,然后选择需要找回的虚拟机vbox,点击打开按钮即可:2、如果打开后报错,则执行第三步:3、删除ubuntu.vbox,然后将ubuntu.vbox-prev重命名为ubuntu.vbox,然后再执行第二步即可...
参见:https://blog.csdn.net/weixin_38883338/article/details/82153933 https://blog.csdn.net/github_39533414/article/details/85211012
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netplan 基于 YAML 的配置系统,使得配置过程非常简单。Netplan 替换了我们之前在 Ubuntu 中用于配置网络接口的旧配置文件/etc/network/interfaces。在本文中,我们将学习如何使用 Netplan 在 Ubuntu 中配置网络。我们将看到静态和动态 IP 配置。我将使用 Ubuntu 18.04 LTS 来描述本文中提到的过程。使用 Netplan 配置网络您可以在/etc
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问,该 URL 代表一种“替代名称”,用于标识提供该服务的服务器的 IP 地址和端口。同一台机器可以同时在不同的端口上提供不同的服务。出于安全原因,可能需要屏蔽 Web 服务的端口号,从而在外部显示与服务实际侦听的端口号不对应的端口号。感谢本教程,您将能够管理您的服务器端口,配置集成在 Ubuntu 中的 UFW 防火墙。特别是,按照指南的说明,您将学习将来自某个端口的请求转发到另一个端口(端口转发),同时使用后者提供的.
Observium 是一个免费和开源的 sa 网络管理和监控系统工具。我们可以使用 SNMP 收集数据,它允许监控所有网络设备。它提供了一个简单易用的 Web 界面。它基于 PHP 并使用 MySQL 数据库来存储数据。在 ubuntu 上设置 Observium 有几个步骤:第 1 步:更新系统。apt-get update第 2 步:安装 PHP 和模块。apt install wget apache2 php php-{pear,cgi,common,curl,mbstring,g
从 20.04 开始,Ubuntu 决定更新实时服务器安装程序以实现自动安装规范,以便能够仅使用 Subiquity 完全自动化安装过程。Subiquity 是新的服务器安装程序(又名“服务器无处不在”),旨在取代之前基于 debian-installer 的经典系统。本文说明了如何使用 Packer 和 Proxmox 上的 Subiquity 生成 Ubuntu Server 20.04 图像模板。介绍Subiquity 仅在live图像文件版本中可用(例如ubuntu-20.0...
Ubuntu 将停止支持 Debian 安装程序(预置)。Ubuntu Server 20.04 附带了一种新的自动化操作系统安装方法,称为带有 subiquity 服务器安装程序的自动安装。这篇文章展示了使用新安装程序构建的打包程序。此设置仅适用于 Ubuntu-20.04 live-server 而不是旧版。SubiquitySubiquity 是 Ubuntu 服务器的新自动安装程序,它是在 18.04 中引入的。自动安装的设置由 cloud-init 配置提供。如果设置,将从配置文件.
此页面的目的是提供在您机器上的 VM 中执行自动安装的简单说明。此页面假设您使用的是 amd64 架构。s390x也有一个版本。通过网络提供自动安装数据这种方法是最容易推广到完全基于网络的安装的方法,在这种安装中,机器会进行网络引导,然后自动安装。下载 ISO转到20.04 ISO 下载页面并下载最新的 Ubuntu 20.04 实时服务器 ISO。挂载 ISOsudo mount -r ~/Downloads/ubuntu-20.04-live-server-amd64...