一、簡單介紹
[root@nginx ~]# ifconfig
eth0(第一張網卡,第二張就是eth1)
Link encap:Ethernet(封裝方式-以太網) HWaddr 08:00:27:23:43:11(MAC地址)
inet addr:192.168.11.32(IP) Bcast:192.168.11.255(廣播) Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe23:4311/64 Scope:Link (IPv6不用管)
UP(當前狀態) BROADCAST RUNNING MULTICAST MTU:1500(最大存儲單元,一次傳輸最大包) Metric:1
(接收的包)RX packets:275960 errors:0 dropped:0 overruns:0 frame:0
(發送的包)TX packets:19786 errors:0 dropped:0 overruns:0 carrier:0
co llisions:0(衝突數,不爲0可能網絡存在故障) txqueuelen:1000(緩衝器長度)
RX bytes:19362794 (18.4 MiB) TX bytes:2371933 (2.2 MiB)
lo是本地環回地址,用於本地通信:
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
二、用法
NAME
ifconfig - configure a network interface
SYNOPSIS
ifconfig [interface]
ifconfig interface [aftype] options | address ...
OPTIONS
interface
The name of the interface. This is usually a driver name followed by a unit number,
for example eth0 for the first Ethernet interface.
up This flag causes the interface to be activated. It is implicitly specified if an
address is assigned to the interface.
down This flag causes the driver for this interface to be shut down.
三、常用使用案例:
(1)[root@nginx ~]# ifconfig eth0 查看eth0的相關信息
(2)[root@nginx ~]# ifconfig eth1 192.168.11.35 broadcast 192.168.11.255 netmask 255.255.255.0 配置IP地址,臨時生效(一般去/etc/sysconfig/network-scripts下配置)
(3) ifconfig eth0 down/up 臨時開啓或關閉網卡。
(4)[root@nginx ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 網卡設備的名稱
TYPE=Ethernet 封裝類型
UUID=eb80df38-3ca2-4cd0-87d6-f38c3054d092
ONBOOT=yes 是否激活網卡,必須打開
NM_CONTROLLED=yes
BOOTPROTO=none 設置IP啓動的方式,有static DHCP 不使用任何方式
HWADDR=08:00:27:23:43:11 MAC地址
IPADDR=192.168.11.32 IP
PREFIX=24 掩碼
GATEWAY=192.168.11.254 網關
DNS1=61.128.128.68 DNS
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
該配置文件修改完成,需要重啓網絡服務:[root@nginx ~]# service network restart