修改網卡命令:
ifconfig eth0 192.168.0.3 netmask 255.255.255.0
⚠️臨時修改IP生效,如果想重啓之後依然生效,可以修改網卡配置文件。
重啓網卡命令:
centos: sudo service network restart
ubuntu:sudo /etc/init.d/networking restart
網卡配置文件:
- centos: 修改 /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #網卡對應的設備別名
BOOTPROTO=static #網卡獲得ip地址的方式(默認爲dhcp,表示自動獲取)
HWADDR=00:07:E9:05:E8:B4 #網卡MAC地址(物理地址)
IPADDR=192.168.100.100 #IP地址
NETMASK=255.255.255.0 #子網掩碼
ONBOOT=yes #系統啓動時是否激活此設備
- ubuntu: 修改 /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
修改dns
# vi /etc/resolv.conf
nameserver 8.8.8.8 #google域名服務器
nameserver 114.144.114.114 #國內域名服務器
ubuntu 參考:http://www.linuxidc.com/Linux/2013-04/83577.htm
centos 參考:http://www.linuxidc.com/Linux/2015-02/112964.htm