Linux網絡屬性配置—ifcfg命令家族

ifcfg命令家族:ifconfig,route,netstat

1、NAME
              ifconfig – configure a network interface
      SYNOPSIS
       ifconfig [interface]
                # ifconfig -a:顯示所有接口,包括inactive狀態的接口;
       ifconfig interface [aftype] options | address …
                # ifconfig  IFACE  IP/MASK  [up|down]
                                ]# ifconfig eth1 192.168.1.100/24
# ifconfig  IFACE  IP  netmask  NETMASK      
                                ]# ifconfig eth1 192.168.1.100 netmask 255.255.255.0
修改和添加IP
  1. [root@node1 ~]# ifconfig eth1 0 #刪除當前IP [root@node1 ~]# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 00:0C:29:AE:E4:E2 inet6 addr: fe80::20c:29ff:feae:e4e2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:145 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16604 (16.2 KiB) TX bytes:1404 (1.3 KiB) [root@node1 ~]# ifconfig eth1 192.168.1.100/24 up [root@node1 ~]# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 00:0C:29:AE:E4:E2 inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feae:e4e2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:145 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16604 (16.2 KiB) TX bytes:1404 (1.3 KiB)
  2. ]# ifconfig eth1:0 192.168.1.101/24 #ifconfig添加IP必須加label,格式 IFACE:#
  3. ]# ifconfig eth1:0 eth1:0 Link encap:Ethernet HWaddr 00:0C:29:AE:E4:E2 inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
開啟和關閉eth1網卡
  1. ]# ifconfig eth1 up
  2. ]# ifconfig eth1 down
2、route命令:路由查看及管理
       route – show / manipulate the IP routing table
路由條目類型:
主機路由:目標地址為單個IP;
網絡路由:目標地址為IP網絡;
默認路由:目標為任意網絡,0.0.0.0/0.0.0.0
查看:# route  -n
  1. [root@node1 ~]# route -n
  2. Kernel IP routing table
  3. Destination Gateway Genmask Flags Metric Ref Use Iface
  4. 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  5. 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
  6. 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
  7. 0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
添加:route  add  [-net|-host]  target  [netmask  Nm]  [gw GW]  [[dev] If]
  1. ]# route add -net 10.0.0.0/8 gw 192.168.1.1 dev eth1
  2. ]# route add default gw 192.168.1.1
  3. ]# route -n
  4. Kernel IP routing table
  5. Destination Gateway Genmask Flags Metric Ref Use Iface
  6. 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  7. 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
  8. 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
  9. 10.0.0.0 192.168.1.1 255.0.0.0 UG 0 0 0 eth1
  10. 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
  11. 0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
           
刪除:route  del  [-net|-host] target  [gw Gw]  [netmask Nm]  [[dev] If]
  1. ]# route del -net 10.0.0.0/8
  2. ]# route del default dev eth1
  3. ]# route -n
  4. Kernel IP routing table
  5. Destination Gateway Genmask Flags Metric Ref Use Iface
  6. 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  7. 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
  8. 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
  9. 0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
3、netstat命令:
  Print network connections, routing tables, interface statistics, masquerade connections, and multicast  memberships
顯示路由表:netstat  -rn
-r:顯示內核路由表
-n:數字格式
  1. ]# netstat -rn
  2. Kernel IP routing table
  3. Destination Gateway Genmask Flags MSS Window irtt Iface
  4. 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  5. 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
  6. 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
  7. 0.0.0.0 10.0.1.2 0.0.0.0 UG 0 0 0 eth0
顯示網絡連接:
netstat  [–tcp|-t]  [–udp|-u]  [–udplite|-U]  [–sctp|-S]  [–raw|-w]  [–listening|-l]  [–all|-a]  [–numeric|-n]   [–extend|-e[–extend|-e]]  [–program|-p]
-t:TCP協議的相關連接,連接均有其狀態;FSM(Finate State Machine);
-u:UDP相關的連接
-w:raw socket相關的連接
-l:處于監聽狀態的連接
-a:所有狀態
-n:以數字格式顯示IP和Port;
-e:擴展格式
-p:顯示相關的進程及PID;
常用組合:
-tan,  -uan,  -tnl,  -unl,  -tunlp
  1. ]# netstat -tan
  2. Active Internet connections (servers and established)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State
  4. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
  5. tcp 0 64 10.0.1.6:22 10.0.1.101:52600 ESTABLISHED
  6. tcp 0 0 :::22 :::* LISTEN
  1. ]# netstat -tnl
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State
  4. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
  5. tcp 0 0 :::22 :::* LISTEN
  1. ]# netstat -tunlp
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 928/sshd
  5. tcp 0 0 :::22 :::* LISTEN 928/sshd
傳輸層協議:
tcp:面向連接的協議;通信開始之前,要建立一個虛鏈路;通信完成后還要拆除連接;
udp:無連接的協議;直接發送數據報文;
顯示接口的統計數據:
netstat    {–interfaces|-I|-i}    [iface]   [–all|-a]   [–extend|-e]   [–verbose|-v]   [–program|-p]  [–numeric|-n]
所有接口:
netstat  -i
指定接口:
netstat  -I<IFace>
  1. ]# netstat -i
  2. Kernel Interface table
  3. Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
  4. eth0 1500 0 4791 0 0 0 3900 0 0 0 BMRU
  5. eth1 1500 0 1442 0 0 0 58 0 0 0 BMRU
  6. lo 65536 0 12 0 0 0 12 0 0 0 LRU
  7. ]# netstat -Ieth1
  8. Kernel Interface table
  9. Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
  10. eth1 1500 0 1446 0 0 0 58 0 0 0 BMRU
ifup/ifdown命令:
注意:通過配置文件/etc/sysconfig/network-scripts/ifcfg-IFACE來識別接口并完成配置;

原創文章,作者:N24_ViCi,如若轉載,請注明出處:http://www.www58058.com/61050

(1)
N24_ViCiN24_ViCi
上一篇 2016-11-27
下一篇 2016-11-27

相關推薦

  • Linux的文件壓縮、解壓之tar的使用

    文件的壓縮   一、壓縮、解壓縮及歸檔工具 壓縮 解壓 后綴(壓縮后) file-roller 圖形操作界面上的使用(略) compress 解壓一:uncompress 或compress -d (注:使用上面的解壓命令,實際上是在屏幕上打印解壓的文件信息,并不是真正上解壓到文件,所以需要在命令后面加上“重定向到指定的文件中”,方可完成解壓。如:…

    Linux干貨 2016-08-18
  • Linux的終端類型

         序  終端的概念是由Ken Thompson提出的,是人機交互的接口。它是一種字符型設備,有多種類型,它大體上分為設備終端,物理終端,虛擬終端,圖形終端,串行終端,偽終端。 一、   設備終端  設備終端就是顯而易見的外在設備,比如鍵盤、鼠標和顯示器等。 二、&nbsp…

    Linux干貨 2016-10-19
  • 我的第一篇博客

    2018.3.26 整理

    2018-03-26
  • SELinux介紹

    SELinux介紹 SELinux: Secure Enhanced Linux, 是美國國家安全局(NSA=The National Security Agency)和SCC(Secure Computing Corporation)開發的 Linux的一個強制訪問控制的安全模塊。 2000年以GNU GPL發布, Linux內核2.6版本后集成在內核中D…

    Linux干貨 2016-10-08
  • 8.1_Linux習題和作業

    7.28 作業 1、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中 1 # cat /etc/issue | tr 'a-z' 'A-Z'whoi > /tmp/issue.out 2、將當前系…

    Linux干貨 2016-08-04
  • linux軟鏈接與硬鏈接的區別

    硬鏈接:相于當給文件增加了一個新名 在添加鏈接時會增加鏈接數,其inode結點數不會增加 支持絕對路徑與相對路徑 硬鏈接不能對目錄來創建 不能跨分區來創建鏈接 硬鏈接鏈接到文件被刪除時,依舊可以通過鏈接文件來訪問被刪文件的數據 軟鏈接:可以支持對目錄來創建鏈接 (注,當你用rm -rf 刪除目錄的時候,目錄不會刪除,但目錄中的內容會被刪除,并且會刪除源文件)…

    Linux干貨 2013-07-15

評論列表(1條)

  • luoweiro
    luoweiro 2016-11-30 23:15

    對于網卡相關的知識,不僅要知道配置方式,也要知道如何查看當前網卡的流量,什么時候流量是高,什么時候網卡傳輸數據有異常,比如iftop工具等使用。

欧美性久久久久