码迷,mamicode.com
首页 > Web开发 > 详细

ifcfg route netstat

时间:2015-12-25 06:31:05      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:ifcfg route nestat

1,简介

    ifconfig,route.netstat是linux下管理配置网络属性(ip地址,路由,网关等)的常用命令,属于net-tools包。相较于iproute包而言,因为开发时间较早,功能相对简单。建议直接使用iprouteoute包下的ip和ss命令。


2,主要功能

    ifconfig - configure a network interface(配置网络接口)

    netstat  -  Print network connections, routing tables, interface statistics...(查看网络连接,路由表,网络接口统计数据,)

    route - show / manipulate the IP routing table(查看或操作路由表)


3,ifconfig常见用法

    语法:

      ifconfig [interface]

        ifconfig interface [aftype] options | address ...

    

    不带任何参数的ifconfig显示正在工作的网络接口相关信息

        

     ~]# ifconfig

    eth0       Link encap:Ethernet  HWaddr 00:0C:29:8D:98:ED  

              inet addr:172.16.249.212  Bcast:172.16.255.255  Mask:255.255.0.0

              inet6 addr: fe80::20c:29ff:fe8d:98ed/64 Scope:Link

              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

              collisions:0 txqueuelen:1000 

              RX bytes:365641374 (348.7 MiB)  TX bytes:9731997 (9.2 MiB)

    

    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:65536  Metric:1

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

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

              collisions:0 txqueuelen:0 

              RX bytes:714 (714.0 b)  TX bytes:714 (714.0 b)

    (这里有两个接口,分别是etho和lo,lo是本地回环接口,对eth0来说,Ethernet表示以太网,HWaddr后面为mac地址,inet addr:后面为ip地址,然后是广播地址和子网掩码,下面还有一些统计信息)

    要想显示所有接口,请使用ifconfig -a


    ifconfig还可以用来配置ip地址

        ipconfig etho 172.16.0.57/16

        (吧eth0的IP地址改为172.16.0.57,掩码位16位,ifconfig不会更改配置文件,但会通知内核立即做出改变,系统重启后,该地址一般会失效,要想使用静态地址,我这里的系统是centos6.7,请在/etc/sysconfig/network-scripts目录下寻找与网络接口有关的配置文件进行更改,请自行谷歌,百度)


    使用ifconfig打开或关闭网络接口

    ifconfig eth0 up 

    ifconfig eth0 down


4,route常见用法


    直接使用route会显示当前内核路由表    

    ~]# route -n          ### -n表示以数值方式显示

    Kernel IP routing table

    Destination  Gateway      Genmask       Flags  Metric Ref Use Iface

    172.16.0.0   0.0.0.0      255.255.0.0    U     1    0   0  eth0

    0.0.0.0     172.16.0.1    0.0.0.0       UG    0    0   0  eth0

    目标地址   网关       子网掩码    标志

    

    路由条目类型有三种:

        1,主机路由:目标位单个ip

        2,网络路由:目标位ip网络

        3,默认路由:目标任意路由,表示方法为0,0,0,0

    可以使用route添加或删除这三种路由,下面演示添加或删除网路路由用法,添加主机路由的方法很类似。


    比如我想让目标地址为192.16.0.0/24网路的地址都通过接口eth0上的地址172.16.0.1转发,使用

     ~]# route add -net 192.16.0.0/24 gw 172.16.0.1 dev eth

     ~]# route -n

    Kernel IP routing table

    Destination  Gateway     Genmask     Flags Metric Ref Use Iface

    192.16.0.0   172.16.0.1   55.255.255.0  UG    0   0  0  eth0

    172.16.0.0   0.0.0.0     255.255.0.0   U     1   0  0  eth0

    0.0.0.0     172.16.0.1   0.0.0.0      UG   0   0   0  eth0

      

    删除操作很类似

     ~]# route del -net 192.16.0.0/24 dev eth0

     ~]# route -n

    Kernel IP routing table

    Destination Gateway      Genmask       Flags Metric Ref  Use Iface

    172.16.0.0  0.0.0.0      55.255.0.0     U     1   0   0  eth0

    0.0.0.0    172.16.0.1    0.0.0.0       UG    0   0   0  eth0

    

    把eth0添加为默认路由

    route add default eth0


5,netsat常见用法

    netstat的用法非常之多,首先介绍一下常见选项的含义

     -r 显示内核路由表,和route命令类似

    -i 显示所有网络接口,和ifconfig -a类似

    -v 显示“啰嗦”信息

    -n 已数值方式显示

    -e 显示扩展格式信息

   -p 显示相关进程以及pid

    -t 与tcp相关,tcp是一种有状态的连接(LISTEN,ESTABLISHED...) 

    -u 与udp相关

    -w 与裸套接字相关

    -l 显示监听状态的链接

    -a 显示所有相关信息

    常见组合

   

以数值方式显示处于监听状态的tcp的相关信息及其进程

~]# netstat -tnlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address     Foreign Address   State    PID/Program name   

tcp        0      0 0.0.0.0:49319     0.0.0.0:*         LISTEN   1884/rpc.statd      

tcp        0      0 0.0.0.0:111       0.0.0.0:*         LISTEN   1828/rpcbind        

tcp        0      0 0.0.0.0:22        0.0.0.0:*         LISTEN   2249/sshd           

tcp        0      0 127.0.0.1:631     0.0.0.0:*         LISTEN   1926/cupsd          

tcp        0      0 127.0.0.1:25      0.0.0.0:*         LISTEN   2331/master 

可以使用netstat -un类似显示udp相关


ifcfg route netstat

标签:ifcfg route nestat

原文地址:http://8522687.blog.51cto.com/8512687/1728061

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!