设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

对 Linux 专家非常有用的 20 个命令

2013-8-12 13:23| 发布者: 红黑魂| 查看: 2928| 评论: 0|来自: 开源中国编译

摘要: 在这篇文章中我将解释管理Linux 服务器所需的一些命令。41. 命令: ifconfigifconfig用来配置常驻内核的网络接口信息。在系统启动必要时用来设置网络适配器的信息。之后,它通常是只需要在调试时或当系统需要调整时使 ...

在这篇文章中我将解释管理 Linux 服务器所需的一些命令。

41. 命令: ifconfig

ifconfig用来配置常驻内核的网络接口信息。在系统启动必要时用来设置网络适配器的信息。之后,它通常是只需要

在调试时或当系统需要调整时使用。

检查活动网络适配器
01[avishek@tecmint ~]$ ifconfig
02 
03eth0      Link encap:Ethernet  HWaddr 40:2C:F4:EA:CF:0E 
04          inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
05          inet6 addr: fe80::422c:f4ff:feea:cf0e/64 Scope:Link
06          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
07          RX packets:163843 errors:0 dropped:0 overruns:0 frame:0
08          TX packets:124990 errors:0 dropped:0 overruns:0 carrier:0
09          collisions:0 txqueuelen:1000
10          RX bytes:154389832 (147.2 MiB)  TX bytes:65085817 (62.0 MiB)
11          Interrupt:20 Memory:f7100000-f7120000
12 
13lo        Link encap:Local Loopback 
14          inet addr:127.0.0.1  Mask:255.0.0.0
15          inet6 addr: ::1/128 Scope:Host
16          UP LOOPBACK RUNNING  MTU:16436  Metric:1
17          RX packets:78 errors:0 dropped:0 overruns:0 frame:0
18          TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
19          collisions:0 txqueuelen:0
20          RX bytes:4186 (4.0 KiB)  TX bytes:4186 (4.0 KiB)
检查所有的网络适配器

“-a”参数用来显示所有网络适配器(网卡)的详细信息,包括那些停用的适配器。

01[avishek@tecmint ~]$ ifconfig -a
02 
03eth0      Link encap:Ethernet  HWaddr 40:2C:F4:EA:CF:0E 
04          inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
05          inet6 addr: fe80::422c:f4ff:feea:cf0e/64 Scope:Link
06          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
07          RX packets:163843 errors:0 dropped:0 overruns:0 frame:0
08          TX packets:124990 errors:0 dropped:0 overruns:0 carrier:0
09          collisions:0 txqueuelen:1000
10          RX bytes:154389832 (147.2 MiB)  TX bytes:65085817 (62.0 MiB)
11          Interrupt:20 Memory:f7100000-f7120000
12 
13lo        Link encap:Local Loopback 
14          inet addr:127.0.0.1  Mask:255.0.0.0
15          inet6 addr: ::1/128 Scope:Host
16          UP LOOPBACK RUNNING  MTU:16436  Metric:1
17          RX packets:78 errors:0 dropped:0 overruns:0 frame:0
18          TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
19          collisions:0 txqueuelen:0
20          RX bytes:4186 (4.0 KiB)  TX bytes:4186 (4.0 KiB)
21 
22virbr0    Link encap:Ethernet  HWaddr 0e:30:a3:3a:bf:03 
23          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
24          UP BROADCAST MULTICAST  MTU:1500  Metric:1
25          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
26          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
27          collisions:0 txqueuelen:0
28          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
停用网络适配器
1[avishek@tecmint ~]$ ifconfig eth0 down
启用网络适配器
1[avishek@tecmint ~]$ ifconfig eth0 up
指定IP地址到网络适配器

为网络适配器eth0设定IP地址“192.168.1.12”.

1[avishek@tecmint ~]$ ifconfig eth0 192.168.1.12
更改网络适配器eth0的子网掩码
1[avishek@tecmint ~]$ ifconfig eth0 netmask 255.255.255.
更改网络适配器eth0的广播地址
1[avishek@tecmint ~]$ ifconfig eth0 broadcast 192.168.1.255
为网络适配器eth0指定IP地址,子网掩码,广播地址
1[avishek@tecmint ~]$ ifconfig eth0 192.168.1.12 netmask 255.255.255.0 broadcast 192.168.1.255

注Note: 如果你设置一块无线网卡的信息,你可以使用的命令是“iwconfig”.欲知更多ifconfig命令的例子和使用方法,

“15个有用的ifconfig 命令”.

42. 命令: netstat

netstat命令显示各种网络相关的信息,如网络连接,路由表,接口统计,伪装连接,组播成员身份等....

列出所有的网络端口
01[avishek@tecmint ~]$ netstat -a
02 
03Active UNIX domain sockets (servers and established)
04Proto RefCnt Flags       Type       State         I-Node   Path
05unix  2      [ ACC ]     STREAM     LISTENING     741379   /run/user/user1/keyring-I5cn1c/gpg
06unix  2      [ ACC ]     STREAM     LISTENING     8965     /var/run/acpid.socket
07unix  2      [ ACC ]     STREAM     LISTENING     18584    /tmp/.X11-unix/X0
08unix  2      [ ACC ]     STREAM     LISTENING     741385   /run/user/user1/keyring-I5cn1c/ssh
09unix  2      [ ACC ]     STREAM     LISTENING     741387   /run/user/user1/keyring-I5cn1c/pkcs11
10unix  2      [ ACC ]     STREAM     LISTENING     20242    @/tmp/dbus-ghtTjuPN46
11unix  2      [ ACC ]     STREAM     LISTENING     13332    /var/run/samba/winbindd_privileged/pipe
12unix  2      [ ACC ]     STREAM     LISTENING     13331    /tmp/.winbindd/pipe
13unix  2      [ ACC ]     STREAM     LISTENING     11030    /var/run/mysqld/mysqld.sock
14unix  2      [ ACC ]     STREAM     LISTENING     19308    /tmp/ssh-qnZadSgJAbqd/agent.3221
15unix  2      [ ACC ]     STREAM     LISTENING     436781   /tmp/HotShots
16unix  2      [ ACC ]     STREAM     LISTENING     46110    /run/user/ravisaive/pulse/native
17unix  2      [ ACC ]     STREAM     LISTENING     19310    /tmp/gpg-zfE9YT/S.gpg-agent
18....
显示所有tcp相关端口
01[avishek@tecmint ~]$ netstat -at
02 
03Active Internet connections (servers and established)
04Proto Recv-Q Send-Q Local Address           Foreign Address         State     
05tcp        0      0 localhost:mysql         *:*                     LISTEN    
06tcp        0      0 *:5901                  *:*                     LISTEN    
07tcp        0      0 *:5902                  *:*                     LISTEN    
08tcp        0      0 *:x11-1                 *:*                     LISTEN    
09tcp        0      0 *:x11-2                 *:*                     LISTEN    
10tcp        0      0 *:5938                  *:*                     LISTEN    
11tcp        0      0 localhost:5940          *:*                     LISTEN    
12tcp        0      0 ravisaive-OptiPl:domain *:*                     LISTEN    
13tcp        0      0 ravisaive-OptiPl:domain *:*                     LISTEN    
14tcp        0      0 localhost:ipp           *:*                     LISTEN    
15tcp        0      0 ravisaive-OptiPle:48270 ec2-23-21-236-70.c:http ESTABLISHED
16tcp        0      0 ravisaive-OptiPle:48272 ec2-23-21-236-70.c:http TIME_WAIT 
17tcp        0      0 ravisaive-OptiPle:48421 bom03s01-in-f22.1:https ESTABLISHED
18tcp        0      0 ravisaive-OptiPle:48269 ec2-23-21-236-70.c:http ESTABLISHED
19tcp        0      0 ravisaive-OptiPle:39084 channel-ecmp-06-f:https ESTABLISHED
20...
显示所有连接的统计信息
01[avishek@tecmint ~]$ netstat -s
02 
03Ip:
04    4994239 total packets received
05    0 forwarded
06    0 incoming packets discarded
07    4165741 incoming packets delivered
08    3248924 requests sent out
09    8 outgoing packets dropped
10Icmp:
11    29460 ICMP messages received
12    566 input ICMP message failed.
13    ICMP input histogram:
14        destination unreachable: 98
15        redirects: 29362
16    2918 ICMP messages sent
17    0 ICMP messages failed
18    ICMP output histogram:
19        destination unreachable: 2918
20IcmpMsg:
21        InType3: 98
22        InType5: 29362
23        OutType3: 2918
24Tcp:
25    94533 active connections openings
26    23 passive connection openings
27    5870 failed connection attempts
28    7194 connection resets received
29....


好的!由于某些原因如果你不想解析netstat 输出的主机、端口和用户名称的话 。

1[avishek@tecmint ~]$ netstat -an


好,你可能需要获取的 netstat 持续输出的动态信息,通过传递中断输出指令 (ctrl + c)来停止。

1[avishek@tecmint ~]$ netstat -c

更多关于“netstat”的例子和使用方法,浏览文章“20个netstat 的使用案例”

43. 命令: nslookup

网络实用程序,用于获得互联网服务器的信息。顾名思义,该实用程序将发现通过查询 DNS 域的名称服务器信息。

1[avishek@tecmint ~]$ nslookup tecmint.com
2 
3Server:     192.168.1.1
4Address:    192.168.1.1#53
5 
6Non-authoritative answer:
7Name:   tecmint.com
8Address: 50.16.67.239
查询 邮件 交换器 记录
01[avishek@tecmint ~]$ nslookup -query=mx tecmint.com
02 
03Server:     192.168.1.1
04Address:    192.168.1.1#53
05 
06Non-authoritative answer:
07tecmint.com mail exchanger = 0 smtp.secureserver.net.
08tecmint.com mail exchanger = 10 mailstore1.secureserver.net.
09 
10Authoritative answers can be found from:
查询域名服务器
01[avishek@tecmint ~]$ nslookup -type=ns tecmint.com
02 
03Server:     192.168.1.1
04Address:    192.168.1.1#53
05 
06Non-authoritative answer:
07tecmint.com nameserver = ns3404.com.
08tecmint.com nameserver = ns3403.com.
09 
10Authoritative answers can be found from:
查询DNS记录
01[avishek@tecmint ~]$ nslookup -type=any tecmint.com
02 
03Server:     192.168.1.1
04Address:    192.168.1.1#53
05 
06Non-authoritative answer:
07tecmint.com mail exchanger = 10 mailstore1.secureserver.net.
08tecmint.com mail exchanger = 0 smtp.secureserver.net.
09tecmint.com nameserver = ns06.domaincontrol.com.
10tecmint.com nameserver = ns3404.com.
11tecmint.com nameserver = ns3403.com.
12tecmint.com nameserver = ns05.domaincontrol.com.
13 
14Authoritative answers can be found from:
查询 起始 授权机构
01[avishek@tecmint ~]$ nslookup -type=soa tecmint.com
02 
03Server:     192.168.1.1
04Address:    192.168.1.1#53
05 
06Non-authoritative answer:
07tecmint.com
08    origin = ns3403.hostgator.com
09    mail addr = dnsadmin.gator1702.hostgator.com
10    serial = 2012081102
11    refresh = 86400
12    retry = 7200
13    expire = 3600000
14    minimum = 86400
15 
16Authoritative answers can be found from:
查询端口号

更改使用你想要连接的端口号

1[avishek@tecmint ~]$ nslookup -port 56 tecmint.com
2 
3Server:     tecmint.com
4Address:    50.16.76.239#53
5 
6Name:   56
7Address: 14.13.253.12

更多阅读 8个Nslookup 命令   


酷毙
1

雷人

鲜花

鸡蛋

漂亮

刚表态过的朋友 (1 人)

  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部