查看Linux的IP信息的命令爲ifconfig -a(輸出全部網卡信息,包括未啓用的)
參數 ifconfig eh0(第一塊網卡,根據實際情況選擇相應的網卡號) down(關閉) UP(啓用)
ifconfig 接口 選項|地址
# ifconfig eth0 up # 開啓eth0網卡
# ifconfig eth0 down # 關閉eth0網卡
# ifconfig eth0 -arp # 關閉eth0網卡arp協議
# ifconfig eth0 promisc # 開啓eth0網卡的混合模式
# ifconfig eth0 mtu 1400 # 設置eth0網卡的最大傳輸單元爲1400
# ifconfig eth0 192.168.0.2/24 # 設置eth0網卡IP地址
# ifconfig eth0 192.168.0.2 netmask 255.255.255.0 # 功能同上
centos6.0以後推薦使用ip命令來代替ifconfig命令
ip [選項] 操作對象{link|addr|route...}
# ip link show # 顯示網絡接口信息
# ip link set eth0 upi # 開啓網卡
# ip link set eth0 down # 關閉網卡
# ip link set eth0 promisc on # 開啓網卡的混合模式
# ip link set eth0 promisc offi # 關閉網卡的混個模式
# ip link set eth0 txqueuelen 1200 # 設置網卡隊列長度
# ip link set eth0 mtu 1400 # 設置網卡最大傳輸單元
# ip addr show # 顯示網卡IP信息
# ip addr add 192.168.0.1/24 dev eth0 # 設置eth0網卡IP地址192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網卡IP地址
# ip route list # 查看路由信息
# ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設置192.168.4.0網段的網關爲192.168.0.254,數據走eth0接口
# ip route add default via 192.168.0.254 dev eth0 # 設置默認網關爲192.168.0.254
# ip route del 192.168.4.0/24 # 刪除192.168.4.0網段的網關
# ip route del default # 刪除默認路由
添加ip的方法,可以在安裝操作系統的時候配置,也可以在安裝完操作系統後配置
配置方法是用VI或者VIM編輯器打開/etc/sysconfig/network-scripts/ifcfg-eth0 這個文件
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0" 設備名
NM_CONTROLLED="yes" 設備是否被NetworkManager管理
ONBOOT="no" 開機是否啓動
HWADDR="00:0C:29:59:E2:D3" 硬件地址(MAC地址)
TYPE=Ethernet 類型
BOOTPROTO=none 啓動協議{none|dhcp}
IPADDR=192.168.0.1 IP地址
PREFIX=24 子網掩碼
GATEWAY=192.168.0.254 默認網關
DNS1=202.106.0.20 主DNS
DOMAIN=202.106.46.151 輔助DNS
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 設備UUID編號