天天看點

Ifconfig指令詳細解析

<b>1.</b><b>測試環境:</b>

[root@lvskeep ~]# cat

/etc/redhat-release

CentOS

release 5.4 (Final)

[root@lvskeep ~]# uname -r

2.6.18-164.el5

[root@lvskeep ~]# ifconfig               <b>#</b><b>本機的網絡配置</b>

eth0      Link encap:Ethernet  HWaddr 00:0C:29:BC:7A:11 

          inet addr:10.0.0.30  Bcast:10.0.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:febc:7a11/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:893 errors:0 dropped:0

overruns:0 frame:0

          TX packets:447 errors:0 dropped:0 overruns:0

carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:91733 (89.5 KiB)  TX bytes:84456 (82.4 KiB)

          Interrupt:185 Base address:0x1400

          inet addr:192.168.0.30  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

          RX packets:25 errors:0 dropped:0

          TX packets:44 errors:0 dropped:0

overruns:0 carrier:0

          RX bytes:6622 (6.4 KiB)  TX bytes:7942 (7.7 KiB)

          Interrupt:169 Base address:0x1480

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:16 errors:0 dropped:0

          TX packets:16 errors:0 dropped:0

          collisions:0 txqueuelen:0

          RX bytes:1224 (1.1 KiB)  TX bytes:1224 (1.1 KiB)

說明:

eth0 表示第一塊網卡, 其中 HWaddr 表示網卡的實體位址,我們可以看到目前這

個網卡的實體位址(MAC位址)是 00:0C:29:BC:7A:1B ; inet addr 用來表示網卡

的IP位址,此網卡的 IP位址是 10.0.0.30, 廣播位址,

Bcast:10.0.0.255,掩碼位址Mask:255.255.255.0

lo 是表示主機的回壞位址,這個一般是用來測試一個網絡程式,但又不想讓局域

網或外網的使用者能夠檢視,隻能在此台主機上運作和檢視所用的網絡接口。比如我

們把HTTPD伺服器的指定到回壞位址,在浏覽器輸入 127.0.0.1 就能看到你所架

WEB網站了。但隻是您能看得到,區域網路的其它主機或使用者無從知道;

<b>2.</b><b>通過man指令檢視系統自帶的幫助</b>

[root@lvskeep ~]# man ifconfig

NAME

       ifconfig - configure a network interface

SYNOPSIS   #摘要,概要,大意

       ifconfig [interface]

       ifconfig interface [aftype] options |

address ...

DESCRIPTION

       Ifconfig is used to configure the

kernel-resident network interfaces.  It

is used at boot time to set up interfaces as necessary.  After that, it is usually only needed when

debugging or when system tuning  is

needed.

If no arguments are given,

ifconfig displays the status of the currently active interfaces.  If a single interface argument is given, it

displays the status of the given interface only; if a single -a argument is  given, it displays the status of all

interfaces, even those that are down.  Otherwise, it configures an interface.

Address

Families

       If the first argument after the

interface name is recognized as the name of a supported address family,that

address family is used for decoding and displaying all protocol addresses.  Currently supported address families include

inet (TCP/IP, default), inet6 (IPv6), ax25 (AMPR Packet Radio), ddp  (Appletalk

Phase

2), ipx (Novell IPX) and netrom (AMPR Packet radio).  All numbers supplied as parts in IPv4 dotted

decimal notation may be decimal, octal, or hexadecimal, as specified in the ISO

C standard (that is, a leading 0x or 0X implies hexadecimal; otherwise, a

leading implies octal; otherwise,the number is interpreted as decimal). Use of

hexamedial and octal numbers is not RFC-compliant and therefore its  use is discouraged and may go away.

OPTIONS

       <b>Interface   #e.g eth0</b><b>、eth1</b>

              The  name of the interface.  This is usually a driver name followed by a

unit number, for example eth0 for the first Ethernet interface.

e.g

[root@lvskeep ~]# ifconfig

eth0

          inet addr:10.0.0.30  Bcast:10.0.0.255  Mask:255.255.255.0

          RX packets:673 errors:0 dropped:0 overruns:0 frame:0

          TX packets:338 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:68647 (67.0 KiB)  TX

bytes:66442 (64.8 KiB)

 <b>up</b>     This flag causes the interface to be activated.  It is implicitly  specified  if  an  address  is assigned to the interface.

在虛拟機上執行ifconfig eth0 up指令,激活eth0

[root@lvskeep ~]# ifconfig eth0 up

[root@lvskeep ~]# ifconfig              <b>#</b><b>驗證是否激活</b>

          RX packets:893 errors:0 dropped:0 overruns:0

frame:0

          TX packets:447 errors:0 dropped:0

eth1      Link encap:Ethernet  HWaddr 00:0C:29:BC:7A:1B 

lo        Link encap:Local Loopback 

看到eth0已經成功激活

<b>down </b>  This flag causes the

driver for this interface to be shut down.

SecureCRT軟體

eth0 down

結果:光标不停閃爍

直接在虛拟機裡操作

eth1      Link

encap:Ethernet  HWaddr 00:0C:29:BC:7A:1B 

          inet

addr:192.168.0.30  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST

RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:25

errors:0 dropped:0 overruns:0 frame:0

          TX packets:44

errors:0 dropped:0 overruns:0 carrier:0

          collisions:0

txqueuelen:1000

          RX bytes:6622 (6.4

KiB)  TX bytes:7942 (7.7 KiB)

          Interrupt:169 Base

address:0x1480

lo        Link encap:Local

Loopback 

          inet6 addr:

::1/128 Scope:Host

          UP LOOPBACK

RUNNING  MTU:16436  Metric:1

          RX packets:16

          TX packets:16

txqueuelen:0

          RX bytes:1224 (1.1

KiB)  TX bytes:1224 (1.1 KiB)

說明:執行ifconfig eth0 down指令後,網卡eth0就停掉了,不工作了,已經斷開了連接配接,而SecureCRT就是通過eth0連接配接的虛拟機,是以光标會一直閃爍;通過在虛拟機上執行ifconfig指令驗證,eth0确實停掉了。

       <b>[-]arp</b> Enable or disable the use of the ARP protocol on this interface.

[root@lvskeep ~]# ifconfig eth0 –arp            <b> #</b><b>關閉了ARP協定</b>

執行完此指令後,SecureCRT和虛拟機斷開連接配接。關閉ARP,IP位址和MAC位址失去了對應關系,無法識别對應的主機。

[root@lvskeep ~]# ifconfig eth0 arp               <b>#</b><b>開啟ARP協定</b>

再次連接配接正常   <b>arp  </b><b>指令(附錄一)</b>

<b>[-]promisc</b>

              Enable or disable the promiscuous

mode of the interface.  If selected, all

packets on the network will be received by the interface.

       <b>[-]allmulti</b>

              Enable or disable all-multicast

mode.  If selected, all multicast packets

on the network will  be received by the

interface.

       <b>metric</b>

N   #指定在計算資料包的轉送次數時,所要加上的數目<b></b>

              This parameter sets the interface

metric.

       <b>mtu</b>

N  This parameter sets the Maximum

Transfer Unit (MTU) of an interface.

              #設定網絡裝置的MTU

       <b>dstaddr</b>

addr

              Set the remote IP address for a

point-to-point link (such as PPP).  This

keyword is now obsolete;use the pointopoint keyword instead.

       <b>netmask</b>

              Set the IP network mask for this

interface.  This value defaults to the

usual class  A,  B  or  C network mask (as derived

from the interface IP address), but it can be set to any value.

[root@lvskeep ~]# ifconfig eth1

192.168.0.30 netmask 255.255.0.0    #子網路遮罩

          inet addr:192.168.0.30  Bcast:192.168.255.255  Mask:255.255.0.0

          UP BROADCAST RUNNING NOARP

MULTICAST  MTU:1500  Metric:1

          TX packets:54 errors:0 dropped:0

          RX bytes:6622 (6.4 KiB)  TX bytes:11144 (10.8 KiB)

注意:netmask不能大寫

       <b>add</b>

addr/prefixlen

              Add an IPv6 address to an

interface. #設定網絡裝置IPv6的IP位址

       <b>del</b><b> addr/prefixlen</b>

              Remove an IPv6 address from an

interface.# 删除網絡裝置IPv6的IP位址

       <b>tunnel</b>

aa.bb.cc.dd

              Create a new SIT (IPv6-in-IPv4)

device, tunnelling to the given destination.  #建立IPv4與IPv6之間的隧道通信位址

       <b>irq</b>

              Set  the  interrupt  line  used by this device.  Not all devices can dynamically change their

IRQ setting.# 置網絡裝置的IRQ

      <b> io_addr addr  </b>#設定網絡裝置的I/O位址<b></b>

              Set the start address in I/O

space for this device.

       <b>mem_start</b>

addr    #設定網絡裝置在主記憶體所占用的起始位址<b></b>

              Set the start address for shared

memory used by this device.  Only a few

devices need this.

       <b>media</b>

type     #設定網絡裝置的媒介類型<b></b>

              Set the physical port or medium

type to be used by the device.  Not all

devices can  change this setting,  and  those  that  can  vary  in  what values they support.  Typical values for type are 10base2 (thin

Ethernet), 10baseT (twisted-pair 10Mbps Ethernet), AUI (external  transceiver)and so on. The special medium

type of auto can be used to tell the driver to auto-sense the media.Again, not

all drivers can do this.

       [-]broadcast [addr] #将要送往指定位址的資料包當成廣播資料包來處理

              If the address argument is given, set

the protocol broadcast address for this interface.Other-wise, set (or clear)

the IFF_BROADCAST flag for the interface.

       <b>[-]pointopoint</b>

[addr] # 與指定位址的網絡裝置建立直接連線,此模式具有保密功能。

              This  keyword  enables  the point-to-point mode

of an interface, meaning that it is a direct link between two machines with

nobody else listening on it. If the address argument is also given, set the

protocol address of the other side  of  the  link,just  like the obsolete dstaddr keyword does.  Otherwise, set or clear the IFF_POINTOPOINT flag for the interface.

       <b>hw</b>

class address

              Set the hardware address of this

interface, if the device driver supports  this  operation.   The

       <b>multicast</b>

              Set  the  multicast  flag on the interface. This should not

normally be needed as the drivers set the flag correctly themselves.

       <b>address</b>

              The IP address to be assigned to

this interface.

       <b>txqueuelen</b>

length

              Set the length of the transmit

queue of the device. It is useful to set this to small values  for slower  devices  with a high latency

(modem links, ISDN) to prevent fast bulk transfers from dis-

              turbing interactive traffic like

telnet too much.

NOTES

       Since kernel release 2.2 there are no

explicit interface statistics for alias  interfaces  anymore.  The statistics  printed  for the original address are shared with all alias addresses on the same

device. If  you want per-address statistics

you should add explicit accounting rules for the address using  the ipchains(8) command.

Interrupt  problems  with Ethernet device drivers fail with EAGAIN. See

http://www.scyld.com/expert/irq-conflict.html for more information.

FILES

       /proc/net/socket

       /proc/net/dev

       /proc/net/if_inet6

BUGS

       While appletalk DDP and IPX addresses

will be displayed they cannot be altered by this command.

SEE

ALSO

       route(8), netstat(8), arp(8), rarp(8),

ipchains(8)

AUTHORS

       Fred N. van Kempen,

       Alan Cox,

       Phil Blundell,

       Andi Kleen

net-tools                       14 August 2000                     IFCONFIG(8)

<b>執行個體:</b>

<b>1.</b><b>如果我們想知道主機所有網絡接口的情況,請用下面的指令:</b>

<b>[root@lvskeep</b>

~]# ifconfig -a

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:2974 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1342 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:280167 (273.6 KiB)  TX

bytes:214214 (209.1 KiB)

          UP BROADCAST RUNNING NOARP MULTICAST  MTU:1500  Metric:1

          RX packets:25 errors:0 dropped:0 overruns:0 frame:0

          TX packets:66 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:6622 (6.4 KiB)  TX bytes:14376 (14.0 KiB)

          RX packets:108 errors:0 dropped:0 overruns:0 frame:0

          TX packets:108 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:11816 (11.5 KiB)  TX

bytes:11816 (11.5 KiB)

sit0      Link encap:IPv6-in-IPv4 

          NOARP  MTU:1480  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          RX bytes:0 (0.0 b)  TX bytes:0

(0.0 b)

<b>2.</b><b>如果我們想檢視某個端口,比如我們想檢視eth1 的狀态,就可以用下面的方法</b>

~]# ifconfig eth1

          RX bytes:6622 (6.4 KiB)  TX

bytes:14376 (14.0 KiB)

<b>ifconfig </b><b>配置網絡端口的方法</b>

<b>ifconfig </b><b>工具配置網絡接口的方法是通過指令的參數來達到目的的</b>

<b>ifconfig  </b><b>網絡端口  IP位址    hw   MAC位址  netmask  掩碼位址   </b>

<b>broadcast  </b><b>廣播位址   [up/down]</b>

<b>3.</b><b>用ifconfig 來調試 eth1網卡的位址</b>

eth1 down

eth1 192.168.1.30 broadcast 192.168.1.255 netmask 255.255.255.0

eth1 up

eth1

          inet addr:192.168.1.30  Bcast:192.168.1.255  Mask:255.255.255.0

          TX packets:91 errors:0 dropped:0 overruns:0 carrier:0

bytes:21736 (21.2 KiB)

第一行:ifconfig eth0 down 表示如果eth0是激活的,就把它DOWN掉。此指令等同于 ifdown eth0;

第二行:用ifconfig 來配置 eth0的IP位址、廣播位址和網絡掩碼;

第三行:用ifconfig eth0 up 來激活eth0 ; 此指令等同于 ifup eth0

第四行:用 ifconfig eth0 來檢視 eth0的狀态;

也可以用直接在指令IP位址、網絡掩碼、廣播位址的同時,激活網卡;要加up參數

[root@lvskeep ~]# ifconfig eth1 192.168.1.30

broadcast 192.168.1.255 netmask 255.255.255.0 up

<b>4.</b><b>設定網卡eth1的IP位址、網絡掩碼、廣播位址,實體位址并且激活它</b>

<b>[root@lvskeep ~]# ifconfig</b>

eth1 192.168.0.30 hw ether 00:0C:29:BC:7A:1<b>1</b><b> broadcast 192.168.0.255 netmask 255.255.255.0 up</b>

<b>SIOCSIFHWADDR: Device or</b>

resource busy

<b>先停掉然後再改,MAC位址最好别改,很容易出錯,</b><b>個人了解。</b><b></b>

繼續閱讀