root@raspberrypi:~# apt install vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libgpm2 vim-runtime
Suggested packages:
gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
libgpm2 vim vim-runtime
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+rpt2+rpi1+deb11u5) ...
root@raspberrypi:~# echo "set mouse-=a" >>~/.vimrc
root@raspberrypi:~# vim /etc/wpa_supplicant/wpa_supplicant.conf
root@raspberrypi:~#
root@raspberrypi:~# iwlist wlan0 scan
# 算一个加密的配置
root@raspberrypi:~# wpa_passphrase winse
# reading passphrase from stdin
xxx
network={
ssid="winse"
#psk="xxx"
psk=xxx
}
root@raspberrypi:~# cat /etc/wpa_supplicant/wpa_supplicant.conf
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="winse"
#psk="xxx"
psk=xxx
}
# 配置服务
pi@raspberrypi:~ $ cat /lib/systemd/system/wpa_supplicant.service
[Unit]
Description=WPA supplicant
Before=network.target
After=dbus.service
Wants=network.target
IgnoreOnIsolate=true
[Service]
#Type=dbus
#BusName=fi.w1.wpa_supplicant1
Type=forking
ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0 -B -D wext
Restart=always
[Install]
WantedBy=multi-user.target
#Alias=dbus-fi.w1.wpa_supplicant1.service
pi@raspberrypi:~ $ cat /etc/systemd/system/dhclient.service
[Unit]
Description= DHCP Client
Before=network.target
[Service]
Type=forking
ExecStart=/sbin/dhclient wlan0 -v
ExecStop=/sbin/dhclient wlan0 -r
Restart=always
[Install]
WantedBy=multi-user.target
pi@raspberrypi:~ $
root@raspberrypi:~# systemctl daemon-reload
root@raspberrypi:~# systemctl stop NetworkManager
root@raspberrypi:~# systemctl enable wpa_supplicant.service
root@raspberrypi:~# systemctl enable dhclient.service
Created symlink /etc/systemd/system/multi-user.target.wants/dhclient.service → /etc/systemd/system/dhclient.service.
root@raspberrypi:~# ip link show wlan0
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:5a:39:e1:4d:bb brd ff:ff:ff:ff:ff:ff
root@raspberrypi:~# ip link set wlan0 up
root@raspberrypi:~# ip link show wlan0
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:5a:39:e1:4d:bb brd ff:ff:ff:ff:ff:ff
root@raspberrypi:~#
root@raspberrypi:~# iw wlan0 link
Not connected.
root@raspberrypi:~# ifconfig wlan0 down
root@raspberrypi:~# ifconfig wlan0 up
root@raspberrypi:~# ifconfig wlan0
wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:5a:39:e1:4d:bb txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Auto Connect on Startup
To automatically connect to wireless network at boot time, we need to edit the wpa_supplicant.service file. It’s a good idea to copy the file from /lib/systemd/system/ directory to /etc/systemd/system/ directory, then edit it because we don’t want newer version of wpasupplicant to override our modifications.
sudo cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service
sudo nano /etc/systemd/system/wpa_supplicant.service
Find the following line.
ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
Change it to the following. Obviously you need to change wlp3s0 if that isn’t your interface name.
ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlp3s0
It’s recommended to always try to restart wpa_supplicant when failure is detected. Add the following right below the ExecStart line.
Restart=always
If you can find the following line in this file, comment it out (Add the # character at the beginning of the line).
Alias=dbus-fi.w1.wpa_supplicant1.service
Save and close the file. Then enable wpa_supplicant service to start at boot time.
sudo systemctl enable wpa_supplicant.service
~~~
sudo nano /etc/systemd/system/dhclient.service
Put the following text into the file.
[Unit]
Description= DHCP Client
Before=network.target
[Service]
Type=forking
ExecStart=/sbin/dhclient wlp3s0 -v
ExecStop=/sbin/dhclient wlp3s0 -r
Restart=always
[Install]
WantedBy=multi-user.target
Save and close the file. Then enable this service.
sudo systemctl enable dhclient.service