通过同一个 WiFi 适配器连接无线 DSL

通过同一个 WiFi 适配器连接无线 DSL

我已经开始使用 Ubuntu 16.04 LTS。我缺少通过同一个 wifi 接口将我的 wifi 连接或无线宽带共享到我的 android 手机的功能。

我在网上搜索了很多,并阅读了有关 kde-nm-connection-editor 和 hostapd 的信息。但似乎没有一个对我有用。

我进入了这个页面,问题的作者提供了一个非常简单的解决方法来解决这个问题。 这是上一个问题的超级用户页面的链接。

我已非常仔细地遵循了所有步骤,但仍遇到困难。

我按照你说的做了,但运行时仍然无法启动 APhostapd -B /etc/hostapd.conf

我收到了错误

$ sudo hostapd -B /etc/hostapd.conf
Configuration file: /etc/hostapd.conf
Could not set interface ap0 flags (UP): Name not unique on network
nl80211: Could not set interface 'ap0' UP
nl80211: deinit ifname=ap0 disabled_11b_rates=0
nl80211 driver initialization failed.
ap0: interface state UNINITIALIZED->DISABLED
ap0: AP-DISABLED 
hostapd_free_hapd_data: Interface ap0 wasn't started

我尝试将接入点的名称从 new 1 更改为其他名称(如 ap0),但仍然不起作用。请帮忙。

我已附加该/etc/hostapd.conf文件以供参考。

interface=ap0
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ssid=wtf
country_code=us
hw_mode=g
channel=10
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
eap_server=0
wpa=2
wpa_passphrase=12345678
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP

编辑 1:运行以下命令后,输出如下:

**iwconfig**
wlp3s0    IEEE 802.11bgn  ESSID:"ABESIT 1"  
          Mode:Managed  Frequency:2.462 GHz  Access Point: 00:04:56:AC:CB:90   
          Bit Rate=43.3 Mb/s   Tx-Power=15 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=56/70  Signal level=-54 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:43   Missed beacon:0

enp2s0    no wireless extensions.

lo        no wireless extensions.

ppp0      no wireless extensions.

**ip link show**
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 20:89:84:ea:88:84 brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 48:d2:24:4c:15:1d brd ff:ff:ff:ff:ff:ff
5: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 3
    link/ppp 

 **iw list**  
Wiphy phy0  
    max # scan SSIDs: 4  
    max scan IEs length: 2257 bytes  
    Retry short limit: 7  
    Retry long limit: 4  
    Coverage class: 0 (up to 0m)  
    Device supports RSN-IBSS.  
    Device supports AP-side u-APSD.  
    Device supports T-DLS.  
    Supported Ciphers:  
        * WEP40 (00-0f-ac:1)  
        * WEP104 (00-0f-ac:5)  
        * TKIP (00-0f-ac:2)  
        * CCMP (00-0f-ac:4)  
        * 00-0f-ac:10  
        * GCMP (00-0f-ac:8)  
        * 00-0f-ac:9  
        * CMAC (00-0f-ac:6)  
        * 00-0f-ac:13  
        * 00-0f-ac:11  
        * 00-0f-ac:12  
    Available Antennas: TX 0x1 RX 0x1  
    Configured Antennas: TX 0x1 RX 0x1  
    Supported interface modes:  
         * IBSS  
         * managed  
         * AP  
         * AP/VLAN  
         * WDS  
         * monitor  
         * mesh point  
         * P2P-client  
         * P2P-GO  
         * Unknown mode (11)  
    Band 1:  
        Capabilities: 0x116e  
            HT20/HT40  
            SM Power Save disabled  
            RX HT20 SGI  
            RX HT40 SGI  
            RX STBC 1-stream  
            Max AMSDU length: 3839 bytes  
            DSSS/CCK HT40  
        Maximum RX AMPDU length 65535 bytes (exponent: 0x003)  
        Minimum RX AMPDU time spacing: 8 usec (0x06)  
        HT TX/RX MCS rate indexes supported: 0-7  
        Bitrates (non-HT):  
            * 1.0 Mbps  
            * 2.0 Mbps (short preamble supported)   
            * 5.5 Mbps (short preamble supported)  
            * 11.0 Mbps (short preamble supported)  
            * 6.0 Mbps  
            * 9.0 Mbps  
            * 12.0 Mbps  
            * 18.0 Mbps  
            * 24.0 Mbps  
            * 36.0 Mbps  
            * 48.0 Mbps  
            * 54.0 Mbps  
        Frequencies:  
            * 2412 MHz [1] (20.0 dBm)  
            * 2417 MHz [2] (20.0 dBm)  
            * 2422 MHz [3] (20.0 dBm)  
            * 2427 MHz [4] (20.0 dBm)  
            * 2432 MHz [5] (20.0 dBm)  
            * 2437 MHz [6] (20.0 dBm)  
            * 2442 MHz [7] (20.0 dBm)  
            * 2447 MHz [8] (20.0 dBm)  
            * 2452 MHz [9] (20.0 dBm)  
            * 2457 MHz [10] (20.0 dBm)  
            * 2462 MHz [11] (20.0 dBm)  
            * 2467 MHz [12] (20.0 dBm) (no IR)  
            * 2472 MHz [13] (20.0 dBm) (no IR)  
            * 2484 MHz [14] (disabled)  
    Supported commands:  
         * new_interface  
         * set_interface  
         * new_key  
         * start_ap  
         * new_station  
         * new_mpath  
         * set_mesh_config  
         * set_bss  
         * authenticate  
         * associate  
         * deauthenticate  
         * disassociate  
         * join_ibss  
         * join_mesh  
         * remain_on_channel  
         * set_tx_bitrate_mask  
         * frame  
         * frame_wait_cancel  
         * set_wiphy_netns  
         * set_channel  
         * set_wds_peer  
         * tdls_mgmt  
         * tdls_oper  
         * probe_client  
         * set_noack_map  
         * register_beacons  
         * start_p2p_device  
         * set_mcast_rate  
         * channel_switch  
         * Unknown command (104)  
         * connect  
         * disconnect  
    Supported TX frame types:  
         * IBSS: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * mesh point: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * P2P-device: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
    Supported RX frame types:  
         * IBSS: 0x40 0xb0 0xc0 0xd0  
         * managed: 0x40 0xd0  
         * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0  
         * AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0  
         * mesh point: 0xb0 0xc0 0xd0  
         * P2P-client: 0x40 0xd0  
         * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0  
         * P2P-device: 0x40 0xd0  
    software interface modes (can always be added):  
         * AP/VLAN  
         * monitor  
    valid interface combinations:  
         * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,  
           total <= 2048, #channels <= 1, STA/AP BI must match  
         * #{ WDS } <= 2048,  
           total <= 2048, #channels <= 1, STA/AP BI must match  
    HT Capability overrides:  
         * MCS: ff ff ff ff ff ff ff ff ff ff  
         * maximum A-MSDU length  
         * supported channel width  
         * short GI for 40 MHz  
         * max A-MPDU length exponent  
         * min MPDU start spacing  
    Device supports TX status socket option.  
    Device supports HT-IBSS.  
    Device supports SAE with AUTHENTICATE command  
    Device supports low priority scan.  
    Device supports scan flush.  
    Device supports AP scan.  
    Device supports per-vif TX power setting  
    P2P GO supports CT window setting  
    Driver supports a userspace MPM  
    Device supports active monitor (which will ACK incoming frames)  
    Driver/device bandwidth changes during BSS lifetime (AP/GO mode)  

答案1

valid interface combinations:  
     * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,  
       total <= 2048, #channels <= 1, STA/AP BI must match  
     * #{ WDS } <= 2048,  
       total <= 2048, #channels <= 1, STA/AP BI must match  

上面的输出显示 AP 和站通道必须一致:要么

#channels <= 1

或者

STA/AP BI must match

意思是一样的,即 Station 和 AP 信道必须匹配。因此您不能随意指定任何频道hostapd.conf文件,您必须确保文件中的频道与您已通过管理(或者车站,同样的事情)界面。

至于接口名称,由于某种原因,我现在无法hostapd使用诸如新0新1,但如果我使用wlan0WLAN1一切正常,正如我的帖子所述。

下面有一个简单的 bash 脚本可以为您完成此操作:

#!/bin/bash

#      If you need to debug, uncomment the following statement
#set -x
#      and comment out the "exec" statement.

[ "$USER" != "root" ] && exec sudo $0 "$@"
exec 2>/var/log/$(basename $0).log

if [ $# != 2 ]; then
    echo "Usage $0 interface action"
    echo "where interface is the name of the wireless interface to be used"
    echo "and action is one of start/stop "
    exit 1
fi 


MY_IF=$1
HPID=/tmp/host$USER.pid
DPID=/tmp/dnsm$USER.pid
WPID=/tmp/wpas$USER.pid

[ -x /usr/bin/srm ] && RM=/usr/bin/srm || RM="/bin/rm -f"

stop() {

        kill -9 $(cat $HPID)
        kill -9 $(cat $DPID)
        dhclient -r
        kill -9 $(cat $WPID)
        rm /tmp/*.my_conf
        rm /tmp/*$USER.pid
        iw dev wlan1 del
        ip link set dev $MY_IF down
        ip addr flush dev $MY_IF
        ip link set dev $MY_IF up
        iptables -t nat -D POSTROUTING -o $MY_IF -j MASQUERADE
        service network-manager start
}


my_exit() {

case $1 in
    2)
        echo "wpa_supplicant failed" >>&2 
        ;;
    3)
        echo "dhclient failed" >>&2 
        ;;
    4)
        echo "hostapd failed" >>&2 
        ;;
    5)
        echo "dnsmasq failed" >>&2 
            ;;
esac
    stop >>&2
    exit $1

}



start() {
    service network-manager stop
    iw phy phy0 interface add wlan1 type __ap

    ip addr flush dev $MY_IF
    ip link set dev $MY_IF up
    ip link set dev wlan1 up

    pkill -9 wpa_supplicant
    MYSECRET=$(mktemp /tmp/XXXXXX.my_conf)

    echo -e "Please enter BSSID and Password of the Wifi network which\n"
    echo -e "you wish to connect to:"
    read BSSID PASSWORD
    wpa_passphrase $BSSID $PASSWORD > $MYSECRET 
    wpa_supplicant -B -i $MY_IF -c $MYSECRET -Dnl80211 -P $WPID 1> /dev/null 
    EXIT_CODE=$?
    $RM $MYSECRET
    [[ $EXIT_CODE == 0 ]] && : || my_exit 2 


    pkill -9 dhclient
    dhclient $MY_IF
    [[ $EXIT_CODE == 0 ]] && : || my_exit 3 

    MYTEMPH=$(mktemp /tmp/XXXXXX.my_conf)
    MYTEMPD=$(mktemp /tmp/XXXXXX.my_conf)

    cat > $MYTEMPH <<EOF
interface=wlan1
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ssid=wtf
hw_mode=g
channel=3
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
eap_server=0
wpa=2
wpa_passphrase=12345678
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP
EOF
    pkill -9 hostapd
    /usr/sbin/hostapd -B -P $HPID $MYTEMPH 1> /dev/null
    sleep  3
    ps ax | grep hostapd | grep -v grep >/dev/null
    if [[ ! $? == 0  ]]; then 
        /usr/sbin/hostapd -B -P $HPID $MYTEMPH 1> /dev/null
    fi
    [[ $? == 0 ]] && : || my_exit 4


    echo 1 >/proc/sys/net/ipv4/ip_forward


    ip addr add 10.111.113.1/24 dev wlan1
    cat > $MYTEMPD <<EOF
domain-needed
bogus-priv
dhcp-authoritative
no-dhcp-interface=$MY_IF
no-dhcp-interface=lo
interface=wlan1
server=8.8.8.8
server=8.8.4.4
expand-hosts
dhcp-range=10.111.113.2,10.111.113.100,12h
EOF
    pkill -9 dnsmasq
    dnsmasq  -C $MYTEMPD -x $DPID
    [[ $? == 0 ]] && : || my_exit 5
    iptables -t nat -A POSTROUTING -o $MY_IF -j MASQUERADE

}



case $2 in
        start)
            stop >>&2
            start
            ;;
        stop)
            stop
            ;;
        *) 
            echo "Usage $0 interface action"
            echo "where interface is the name of the wireless interface to be used"
            echo "and action is one of start/stop "
            ;;

esac

确保渠道hostapd.conf 里面上面的脚本(行通道=3)与您要连接的 AP 相匹配。我有不是左上角设置-x,它允许您在脚本执行过程中查看错误(如果有):如果您需要进行一些调试,您可以联合国评论它。我无法做出hostapd,当从上述脚本调用时,可以使用除country_code=us,但你可能更幸运。另外,我的版本hostapd每次都会失败,因此我添加了一个条件来测试hostapd是否正在运行,并尝试恰好再一次使其开始。

相关内容