许多相关的帖子似乎与硬件有关或由于硬件问题,但我似乎没有遇到这些问题,因为只要我在启动后和登录后设置 wlan0,一切都可以正常工作。
我是 ubuntu 服务器的新手,所以我希望这里只是存在配置问题。
我只是想在启动后连接无线,这样我就可以 ssh 进入盒子并一直进行远程工作。
如果我使用 wlan0 设置 /etc/network/interfaces(无论是使用静态设置还是 dhcp),则该卡似乎设置了一个 IP 地址(根据 ifconfig),但ip addr
显示 wlan0 已关闭,并且要求它启动的命令似乎没有任何作用。
如果我删除 /etc/network/interfaces 中的设置,重新启动,登录实际机器,ip addr
显示 wlan0 已启动,然后我运行,sudo dhclient wlan0
那么一切都正常。
答案在这里:系统重启后没有 Wi-Fi暗示启动过程中可能存在时间问题,这似乎合适,但我不确定如何解决这个问题。
以下是/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
address 192.168.1.13
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
pre-up /etc/init.d/wpa.sh start
post-down /etc/init.d/wpa.sh stop
我尝试了 chili555 的建议。对的更改/etc/network/interfaces
没有影响任何东西。启动后,ip addr
显示 wlan0 处于关闭状态,并且此处列出的各种尝试启动它的命令均不起作用。
sudo ifup -v wlan0
即使进行了各种重定向,我也无法捕获所有输出2>&1 >file
,未捕获的部分来自 wpa_supplicant。它没有显示任何我能看出的错误,以下是命令的其余部分sudo ifup
(sudo ifdown 似乎工作正常,输出很少):
OK
ip addr add 192.168.1.13/255.255.255.0 broadcast 192.168.1.255 dev wlan0 label wlan0
ip link set dev wlan0 up
ip route add default via 192.168.1.1 dev wlan0
run-parts --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/000resolvconf
run-parts: executing /etc/network/if-up.d/ethtool
run-parts: executing /etc/network/if-up.d/ntpdate
run-parts: executing /etc/network/if-up.d/openssh-server
run-parts: executing /etc/network/if-up.d/upstart
run-parts: executing /etc/network/if-up.d/wpasupplicant
但ip addr
之后仍然处于 DOWN 状态,我无法连接。我也尝试过sudo ip link set wlan0 up
(有和没有dev
位),但sudo ifconfig wlan0 up
似乎没有任何变化。
运行sudo dhclient ip
只是挂起一会儿然后超时。已经分配了静态 IP,不知道这是否重要。
ip addr
当我在 /etc/network/interfaces 中未配置 wlan0 然后重新启动时,启动后显示的内容如下:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p12p1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f0:4d:a2:4c:6a:c4 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:21:6a:c7:12:38 brd ff:ff:ff:ff:ff:ff
inet6 fe80::221:6aff:fec7:1238/64 scope link
valid_lft forever preferred_lft forever
然后运行sudo dhclient wlan0
连接所有内容,然后得到后续ip addr
输出:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p12p1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f0:4d:a2:4c:6a:c4 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:21:6a:c7:12:38 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::221:6aff:fec7:1238/64 scope link
valid_lft forever preferred_lft forever
答案1
测试一下:
在 /etc/init.d/ 中编写一个脚本,假设为 wifi-on.sh
sudo -i
nano /etc/init.d/wifi-on.sh
使用此内容或使用它来启用 wlan0:
!/bin/bash
ifconfig wlan0 up
iwconfig wlan0 essid <ESSID>
iwconfig wlan0 key s:<password_wireless>
dhclient wlan0
您授予执行权限并添加到系统启动:
sudo -i
chmod 755 /etc/init.d/wifi-on.sh
update-rc.d wifi-on.sh defaults
答案2
我完全不确定你的前置和后置声明在做什么。我建议你将文件修改为:
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
address 192.168.1.13
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
wpa-essid your_network
wpa-psk your_key
请确保您选择的地址超出路由器中 DHCP 服务器使用的地址范围,以免发生冲突。重新启动接口以查看它是否连接或抱怨错误:
sudo ifdown wlan0 && sudo ifup -v wlan0
查看:
ifconfig
ping -c3 www.ubuntu.com
chrismo:这些更改不会/etc/network/interfaces
影响任何东西。启动后,ip addr
显示 wlan0 处于关闭状态,此处列出的各种尝试启动它的命令均不起作用。
sudo ifup -v wlan0
即使进行了各种重定向,我也无法捕获所有输出2>&1 >file
,未捕获的部分来自 wpa_supplicant。它没有显示任何我能看出的错误,以下是命令的其余部分sudo ifup
(sudo ifdown 似乎工作正常,输出很少):
OK
ip addr add 192.168.1.13/255.255.255.0 broadcast 192.168.1.255 dev wlan0 label wlan0
ip link set dev wlan0 up
ip route add default via 192.168.1.1 dev wlan0
run-parts --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/000resolvconf
run-parts: executing /etc/network/if-up.d/ethtool
run-parts: executing /etc/network/if-up.d/ntpdate
run-parts: executing /etc/network/if-up.d/openssh-server
run-parts: executing /etc/network/if-up.d/upstart
run-parts: executing /etc/network/if-up.d/wpasupplicant
但ip addr
之后仍然处于 DOWN 状态,我无法连接。我也尝试过sudo ip link set wlan0 up
(有和没有dev
位),但sudo ifconfig wlan0 up
似乎没有任何变化。
运行sudo dhclient ip
只是挂起一会儿然后超时。已经分配了静态 IP,不知道这是否重要。
ip addr
当我在 /etc/network/interfaces 中未配置 wlan0 然后重新启动时,启动后显示的内容如下:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p12p1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f0:4d:a2:4c:6a:c4 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:21:6a:c7:12:38 brd ff:ff:ff:ff:ff:ff
inet6 fe80::221:6aff:fec7:1238/64 scope link
valid_lft forever preferred_lft forever
然后运行sudo dhclient wlan0
连接所有内容,然后得到后续ip addr
输出:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p12p1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f0:4d:a2:4c:6a:c4 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:21:6a:c7:12:38 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::221:6aff:fec7:1238/64 scope link
valid_lft forever preferred_lft forever