Answer

问题及解答

Xubuntu 下配置网络连接

Posted by haifeng on 2018-11-12 22:09:07 last update 2018-11-12 22:55:14 | Edit | Answers (0)

Step 1. 首先运行 ifconfig 命令,

haifeng@X220i:~\$ ifconfig
enp0s25   Link encap:以太网  硬件地址 xx:xx:xx:xx:xx:xx
          UP BROADCAST MULTICAST  MTU:1500  跃点数:1
          接收数据包:0 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:0 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:1000
          接收字节:0 (0.0 B)  发送字节:0 (0.0 B)
          中断:20 Memory:f2500000-f2520000

lo        Link encap:本地环回  
          inet 地址:127.0.0.1  掩码:255.0.0.0
          inet6 地址: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  跃点数:1
          接收数据包:22901 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:22901 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:1000
          接收字节:2718229 (2.7 MB)  发送字节:2718229 (2.7 MB)

wlp3s0    Link encap:以太网  硬件地址 xx:xx:xx:xx:xx:xx  
          inet 地址:10.0.0.9  广播:10.0.0.255  掩码:255.255.255.0
          inet6 地址: fe80::9012:467c:1ab7:8f64/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1
          接收数据包:3072 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:10145 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:1000
          接收字节:216777 (216.7 KB)  发送字节:1016088 (1.0 MB)



Step 2.  编辑 /etc/network/ 目录下的 interfaces 文件

haifeng@X220i:/etc/network\$ ls
if-down.d  if-post-down.d  if-pre-up.d  if-up.d  interfaces  interfaces.d
haifeng@X220i:/etc/network\$ sudo vim interfaces

内容为:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto wlp3s0
iface wlp3s0 inet dhcp

auto enp0s25
iface enp0s25 inet dhcp
~                                                                               
~


Step 3.  启动有线设备enp0s25 和无线设备 wlp3s0


haifeng@X220i:/etc/network\$ sudo ifup wlp3s0

haifeng@X220i:/etc/network\$ sudo ifup enp0s25
Internet Systems Consortium DHCP Client 4.3.3
Copyright 2004-2015 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/enp0s25/xx:xx:xx:xx:xx:xx
Sending on   LPF/enp0s25/xx:xx:xx:xx:xx:xx
Sending on   Socket/fallback
DHCPDISCOVER on enp0s25 to 255.255.255.255 port 67 interval 3 (xid=0xfad07973)
DHCPDISCOVER on enp0s25 to 255.255.255.255 port 67 interval 8 (xid=0xfad07973)
DHCPDISCOVER on enp0s25 to 255.255.255.255 port 67 interval 12 (xid=0xfad07973)
DHCPDISCOVER on enp0s25 to 255.255.255.255 port 67 interval 18 (xid=0xfad07973)
DHCPDISCOVER on enp0s25 to 255.255.255.255 port 67 interval 12 (xid=0xfad07973)
DHCPREQUEST of 10.0.0.9 on enp0s25 to 255.255.255.255 port 67 (xid=0x7379d0fa)
DHCPOFFER of 10.0.0.9 from 10.0.0.1
DHCPACK of 10.0.0.9 from 10.0.0.1
bound to 10.0.0.9 -- renewal in 42655 seconds.


Step 4. 更改 /etc/resolv.conf 文件, 使用 Google 的公共 DNS (Domain Name System 域名系统)

haifeng@X220i:/etc\$ ls -l resolv.conf
lrwxrwxrwx 1 root root 29 10月  8  2017 resolv.conf -> ../run/resolvconf/resolv.conf

我们可以新建一个 resolv.conf, 内容为

nameserver 114.114.114.114
nameserver 8.8.8.8

重新启动 networking
haifeng@X220i:/etc\$ sudo /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.