Ubuntu Server 16.04 配置靜態ip及動態ip
首先把需要用的指令列出
查看當前網路配置
ifconfig
查看設備擁有的網卡
ip addr
# ip link
查看當前連接商在網卡情況
ip route show
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.110
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.200
重啓網絡命令
systemctl restart networking
# or
# service networking restart
要用到關鍵配置文件列出
網卡配置地址
/etc/network/interfaces
內容大概是這樣的
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
#iface eno1 inet dhcp
iface eth0 inet static
address 192.168.1.119
netmask 255.255.255.0
getway 192.168.1.1
dns-nameserver 1.1.1.1
dns-nameserver 114.114.114.114
dns-nameserver 8.8.8.8
DNS配置地址
/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 0.0.0.0
nameserver 8.8.8.8
/etc/resolv.conf
修改在內容將會立即生效,但是一旦重啓電腦或網絡又會被重置。
通過修改/etc/resolvconf/resolv.conf.d/base
配置文件,再重啓networking可永久生效
配置靜態或動態IP
首先需要先查看網卡的名稱
ip router show
進入網絡配置文件進行修改配置
sudo vi /etc/network/interfaces
配置文件如下
auto eth0
iface eth0 inet dhcp # 動態配置
auto eth1
iface eth1 inet static # 配置靜態
address 192.168.1.100 # ip地址
netmask 255.255.255.0 # 網絡掩碼
gateway 192.168.1.1 # 網關
dns-nameserver 114.114.114.114 # dns服務器,可以設置多個
重啓網絡
sudo service networking restart
查看當前ip
ifconfig