/etc/init.d/networking restart 如何導致 wpa_supplicant 使用先前的設定運行?

/etc/init.d/networking restart 如何導致 wpa_supplicant 使用先前的設定運行?

背景:

我使用 Debian Lenny,有兩個 WiFi 介面。我使用通用配置/etc/network/interfaces

iface wlan0 inet static
        address 10.0.0.1
        network 10.0.0.0
        netmask 255.255.255.0
        broadcast 10.0.0.255

auto wlan1
iface wlan1 inet static
        address 192.168.5.1
        network 192.168.5.1
        netmask 255.255.255.0
        broadcast 192.168.0.25

所以它沒有任何關於 的跡象wpa_supplicant

/etc/wpa_supplicant.conf我手動使用 wpa_supplicant (v2.0) 透過(對於 wlan0)和/etc/wpa_supplicant2.conf(對於 wlan1) 將它們連接到 WLAN 。

問題:

雖然 wifi 介面已連接到 WLAN,但我確實

ip link set wlan0 down
ip link set wlan1 up
rm /var/run/wpa_supplicant/wlan0
rm /var/run/wpa_supplicant/wlan1

那我就這麼做了ip link set wlan0 (and 1) up。在這種情況下,iwconfig 顯示 wifi 介面未連接到任何網路。

之後,我就跑/etc/init.d/networking restart。過程完成後,iwconfig 顯示 wifi 介面已連接到先前連接的 WLAN。

問題:

為什麼/etc/init.d/networking restart會使用先前使用過的介面的 .config 檔案來執行 wpa_supplicant(wlan0 為 wpa_suppliant.conf,wlan1 為 wpa_supplicant2.conf)?我多次重複此過程,每次 wifi 介面都連接到 .config 檔案中定義的相同網路。

我做了什麼:

1)我懷疑該/etc/init.d/networking腳本以某種方式使用了 wpa_supplicant 。於是,我看了一下劇本:

     #!/bin/sh -e
    ### BEGIN INIT INFO
    # Provides:          networking
    # Required-Start:    mountkernfs ifupdown $local_fs
    # Required-Stop:     ifupdown $local_fs
    # Default-Start:     S
    # Default-Stop:      0 6
    # Short-Description: Raise network interfaces.
    ### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"

[ -x /sbin/ifup ] || exit 0

. /lib/lsb/init-functions

process_options() {
    [ -e /etc/network/options ] || return 0
    log_warning_msg "/etc/network/options still exists and it will be IGNORED! R
ead README.Debian of netbase."
}

check_network_file_systems() {
    [ -e /proc/mounts ] || return 0

    exec 9<&0 < /proc/mounts
    while read DEV MTPT FSTYPE REST; do
        case $DEV in
        /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
            log_warning_msg "not deconfiguring network interfaces: network devic
es still mounted."
            exit 0
            ;;
        esac
        case $FSTYPE in
        nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse
.curlftpfs)
            log_warning_msg "not deconfiguring network interfaces: network file 
systems still mounted."
            exit 0
            ;;
        esac
    done
    exec 0<&9 9<&-
}

case "$1" in
start)

        process_options

        log_action_begin_msg "Configuring network interfaces"
        if ifup -a; then
            log_action_end_msg $?
        else
            log_action_end_msg $?
        fi
        ;;

stop)
        check_network_file_systems

        log_action_begin_msg "Deconfiguring network interfaces"
        if ifdown -a --exclude=lo; then
            log_action_end_msg $?
        else
            log_action_end_msg $?
        fi
        ;;

force-reload|restart)
        process_options

        log_action_begin_msg "Reconfiguring network interfaces"
        ifdown -a --exclude=lo || true
        if ifup -a --exclude=lo; then
            log_action_end_msg $?
        else
            log_action_end_msg $?
        fi
        ;;

*)
        echo "Usage: /etc/init.d/networking {start|stop|restart|force-reload}"
        exit 1
        ;;
esac

exit 0

ifupdown是一個在執行 ifdown 之前殺死 wpa_supplicant 的腳本(正如該腳本所解釋的那樣)。我不知道 shell 或 bash 編程,但據我了解,重新啟動僅對介面執行 ifdown 和 ifup 操作。

2)閱讀 ifup 的手冊頁其中說:

ifup 和 ifdown 指令可用來根據檔案 /etc/network/interfaces 中的介面定義來設定(或分別取消設定)網路介面。

my/etc/network/interfaces不包含有關 wpa_supplicant 的任何配置。

相關內容