ubuntu网络配置文件详解 ubuntu配置上网



文章插图
ubuntu网络配置文件详解 ubuntu配置上网

文章插图
Ubuntu 16.04查看IP、网关、DNS等信息
[email protected]:~# cat /proc/version #查看发行版本
Linux version 4.9.40-eve-ng-ukms-2+ ([email protected]) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #4 SMP Fri Sep 15 02:07:02 CEST 2017
[email protected]:~#
查看IP地址:
[email protected]:~# ifconfig
[email protected]:~# ip add show
查看路由、网关(gateway)
[email protected]:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.246.2 0.0.0.0 UG 0 0 0 pnet0
[email protected]:~# route -n #-n 表示不解析名字
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.246.2 0.0.0.0 UG 0 0 0 pnet0
10.163.1.0 0.0.0.0 255.255.255.0 U 0 0 0 pnet1
Flags,如果是U代表活动的路由,出现G代表这个网络接口连接的是网关,H代表是一个主机
[email protected]:~# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.246.2 0.0.0.0 UG 0 0 0 pnet0
10.163.1.0 0.0.0.0 255.255.255.0 U 0 0 0 pnet1
查看DNS
[email protected]:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.246.2
[email protected]:~#
查看网络服务状态
[email protected]:~# systemctl status networking
重启网络服务
[email protected]:~# systemctl restart networking

[email protected]:~# service networking restart
ping命令
[email protected]:~# ping -c 3 192.168.246.2 #向网关ping 3个包
PING 192.168.246.2 (192.168.246.2) 56(84) bytes of data.
64 bytes from 192.168.246.2: icmp_seq=1 ttl=128 time=0.251 ms
64 bytes from 192.168.246.2: icmp_seq=2 ttl=128 time=0.300 ms
64 bytes from 192.168.246.2: icmp_seq=3 ttl=128 time=0.280 ms
— 192.168.246.2 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2039ms
rtt min/avg/max/mdev = 0.251/0.277/0.300/0.020 ms
查看网络接口配置文件
[email protected]:~# cat /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
# The primary network interface
iface eth0 inet manual
auto pnet0
iface pnet0 inet static
address 192.168.246.177
netmask 255.255.255.0
gateway 192.168.246.2
dns-nameservers 192.168.246.2
bridge_ports eth0
bridge_stp off
关闭接口
[email protected]:~# ifdown pnet3
启用接口
[email protected]:~# ifup pnet3
[email protected]:~# ifdown eth0 #想关闭eth0来着,但是系统提示没有配置,估计是eth0没有配置IP地址的原因
ifdown: interface eth0 not configured
[email protected]:~#
查看路由跟踪信息
[email protected]:~# traceroute www.toutiao.com
traceroute to www.toutiao.com (36.156.179.242), 30 hops max, 60 byte packets
1 192.168.246.2 (192.168.246.2) 0.125 ms 0.059 ms 0.084 ms
【ubuntu网络配置文件详解 ubuntu配置上网】2 * * *