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.178linux.com/61050

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

相关推荐

  • samba服务

    一、什么是SAMBA   Linux之间可以通过NFS服务方便的挂载远程主机上的共享目录,那么SAMBA主要是用于实现Windows主机与Linux主机之间共享文件互访。它们之间的通信依赖于CIFS协议。 二、SAMBA使用的daemon     1、nmbd:在Linux上实现NetBIOS;     &n…

    Linux干货 2016-02-14
  • week6

    1、请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白 字符开头的行的行首加#; :%s@^[[:space:]]\+[^[:space:]]@#&@g 2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/…

    Linux干货 2016-12-02
  • 深入了解正则表达式与grep应用

    刚开始学习正则表达式时候,感觉和看无字天书没什么分别,迷茫了一段时间后,仔细去理解,慢慢你会发现也没什么的。认真去钻研了,多练习,是可以理解他们的含义的。也许正如老师所言,学习linux ,入门的确很陡峭,对于我这个基础薄弱,智商低于80的人来说的确很吃力。关于正则概念的就不去描述了,说起来真的不好表达,下面通过一些实例来进行深入理解吧。 1.显示当前系统上…

    2017-11-01
  • B-树和B+树的应用:数据搜索和数据库索引

    B-树 1 .B-树定义 B-树是一种平衡的多路查找树,它在文件系统中很有用。 定义:一棵m 阶的B-树,或者为空树,或为满足下列特性的m 叉树:⑴树中每个结点至多有m 棵子树;⑵若根结点不是叶子结点,则至少有两棵子树; ⑶除根结点之外的所有非终端结点至少有[m/2] 棵子树;⑷所有的非终端结点中包含以下信息数据:    &nb…

    Linux干货 2015-07-30
  • N25第一周博客作业

    本文主要阐述了以下几个知识点: l  计算机的组成及功能; l  介绍各不同发行版的linux及其联系; l  描述linux的哲学思想,及其本人对其个人理解; l  介绍一些linux基本命令及相关选项; l  如何在linux上使用帮助命令; l  罗列出发行版linux上的一些基础目录及其功用…

    Linux干货 2016-11-29
  • Nginx/httpd 代理两个Tomcat

    Nginx 前端代理服务器172.16.71.1 从ftp下载Nginx 安装 vim /etc/nginx/nginx.confhttp {…# 添加以下内容upstream tcsrvs {         server 172.16.71.4:8080;        …

    Linux干货 2017-02-12

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-30 23:15

    对于网卡相关的知识,不仅要知道配置方式,也要知道如何查看当前网卡的流量,什么时候流量是高,什么时候网卡传输数据有异常,比如iftop工具等使用。