码迷,mamicode.com
首页 > 系统相关 > 详细

linux学习命令总结⑩⑥

时间:2014-09-02 02:42:54      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:cccccc   linux   style   网络   接口   

#ifconfig命令:用来查看和配置网络设备

显示当前激活状态的网络接口的信息:

[root@VM_168_102_centos ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:E2:7B:D2  
          inet addr:10.221.168.102  Bcast:10.221.171.255  Mask:255.255.252.0
          inet6 addr: fe80::216:3eff:fee2:7bd2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3689339 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1724548 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:370517889 (353.3 MiB)  TX bytes:211155888 (201.3 MiB)
          Interrupt:163 

简单说明:
eth0:网络接口
link encap:网络类型
HWaddr:网卡物理地址(MAC地址)
Inet addr:IP地址
Bcast:广播地址
Mask:子网掩码
UP:代表网卡开启状态;RUNNING:代表网卡的网线被接上;BROADCAST:支持点对点通讯协议;multicast:支持组播
    MTU:网卡的最大传输单元
RX packets:接收的数据包个数
TX packets:传输的数据包个数
RX byte:接受的具体数目
TX byte:传输的具体数目
Interrupt:终端信息
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: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:1568 (1.5 KiB)  TX bytes:1568 (1.5 KiB)
lo:本地循环接口

显示指定的网络接口:

[root@VM_168_102_centos ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:16:3E:E2:7B:D2  
          inet addr:10.221.168.102  Bcast:10.221.171.255  Mask:255.255.252.0
          inet6 addr: fe80::216:3eff:fee2:7bd2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3694095 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1725551 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:370998440 (353.8 MiB)  TX bytes:211382468 (201.5 MiB)
          Interrupt:163

配置IP地址(立即生效,但并不永久):

ifconfig eth0 192.168.122.22

给eth0网卡配置IP地:192.168.120.56

ifconfig eth0 192.168.122.22 netmask 255.255.255.0(或者192.168.122.22/24)

给eth0网卡配置IP地址:192.168.120.56 ,并加上子掩码:255.255.255.0

启动/关闭指定网络接口:

ifconfig eth0 on

ifconfig eth0 down

设置最大传输单元:

[root@localhost ~]# ifconfig eth0 mtu 1480
[root@localhost ~]# ifconfig eth0 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:44:B7:60  
          inet addr:192.168.108.128  Bcast:192.168.108.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe44:b760/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1480  Metric:1
          RX packets:373 errors:0 dropped:0 overruns:0 frame:0
          TX packets:275 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:37682 (36.7 KiB)  TX bytes:35735 (34.8 KiB)

[root@localhost ~]# ifconfig eth0 mtu 1500
[root@localhost ~]# ifconfig eth0 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:44:B7:60  
          inet addr:192.168.108.128  Bcast:192.168.108.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe44:b760/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:399 errors:0 dropped:0 overruns:0 frame:0
          TX packets:293 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:39932 (38.9 KiB)  TX bytes:38155 (37.2 KiB)

#route命令:用于显示和操作IP路由表

显示当前路由信息:

[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.108.0   *               255.255.255.0   U     0      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
 
简单说明:
Destination:目标主机或目标网络
Gateway:网关地址(*表示目标是本主机所属的网络,不需要路由)
Genmask:网络掩码
Flags标志说明:U:UP表示此路由当前为启动状态;H:表示目标是主机;G:表示路由指向网关
Metric:路由距离,到达指定网络所需的中转数(linux 内核中没有使用)
Ref:路由项引用次数(linux 内核中没有使用)
Use:该路由被使用的次数,可以粗略估计通向指定网络地址的网络流量
Iface:输出接口

route -n: 使用数字格式显示,不反解地址到主机名

添加到主机的路由:

[root@localhost ~]# route add -host 192.168.107.1 gw 192.168.108.25 
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.107.1   192.168.108.25  255.255.255.255 UGH   0      0        0 eth0
192.168.108.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

添加到网络的路由:

route add -net 10.20.30.48 netmask 255.255.255.0 gw 10.20.30.41
route add -net 10.20.30.48/24 gw 10.20.30.41

添加到默认的路由

[root@localhost ~]# route add default gw 192.168.1.55
192.168.107.1   192.168.108.25  255.255.255.255 UGH   0      0        0 eth0
192.168.108.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
0.0.0.0         192.168.108.55  0.0.0.0         UG    0      0        0 eth0

route del:删除路由

删除到主机的路由

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.107.1   192.168.108.25  255.255.255.255 UGH   0      0        0 eth0
192.168.108.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
0.0.0.0         192.168.108.55  0.0.0.0         UG    0      0        0 eth0
[root@localhost ~]# route del -host 192.168.107.1
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.108.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
0.0.0.0         192.168.108.55  0.0.0.0         UG    0      0        0 eth0

删除到网络的路由

route del –net 192.168.1.1

删除到默认的路由

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.108.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
0.0.0.0         192.168.108.55  0.0.0.0         UG    0      0        0 eth0
[root@localhost ~]# route del default
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.108.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

#配置DNS

[root@localhost ~]# vim /etc/resolv.conf 

# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.108.1

linux学习命令总结⑩⑥

标签:cccccc   linux   style   网络   接口   

原文地址:http://putongren.blog.51cto.com/9086263/1547623

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