Linux命令行配置网络(有线网络,无线网络)// Debian

一、有线网卡

1.首先得到网卡名称:ip addr
(或者:  ls /sys/class/net )

2.设置文件为:/etc/network/interfaces
    使用DHCP方式,在文件底部添加:

ethernet

auto enp4s0f2
allow-hotplug enp4s0f2
iface enp4s0f2 inet dhcp

设置静态IP上网,在文件底部添加:

ethernet

auto enp4s0f2
iface enp4s0f2 inet static
    address 192.168.1.120/24
    gateway 192.168.1.1


3.重启网络服务:sudo systemctl restart networking.service
4.查看网卡详情及ping测试:
确认是不是有IP:ip addr

确认是否连接到网络:ping baidu.com

 

二、无线网卡
1.首先得到网卡名称:ip addr
(或者:   ls /sys/class/net )

2.设置文件为:/etc/network/interfaces
设置DHCP方式,在文件底部添加:

wifi

auto wlp3s0
allow-hotplug wlp3s0
iface wlp3s0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

设置静态IP上网,在文件底部添加:        

wifi

auto wlp3s0
iface wlp3s0 inet static
    address 192.168.1.120/24
    gateway 192.168.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

3.配置无线网络
在目录/etc/wpa_supplicant下创建文件wpa_supplicant.conf
        touch /etc/wpa_supplicant/wpa_supplicant.conf
运行程序wpa_passphrase来配置无线网络文件。
        wpa_passphrase ssid password > /etc/wpa_supplicant/wpa_supplicant.conf
文件内容显示如下:
network={
ssid="wifi"

psk="password"

psk=f6374c1c5e193af4c23f7a62e901e282e389c0b4bcd9bb2
}

4.重启网络服务:sudo systemctl restart networking.service
5.查看网卡详情及ping测试:
确认是不是有IP:ip addr

确认是否连接到网络:ping baidu.com