Linux网络管理工具-创新互联-成都快上网建站

Linux网络管理工具-创新互联

一、ifconfig命令

站在用户的角度思考问题,与客户深入沟通,找到正定网站设计与正定网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计制作、网站建设、企业官网、英文网站、手机端网站、网站推广、主机域名、虚拟空间、企业邮箱。业务覆盖正定地区。

ifconfig是linux中用于显示或配置网络设备(网络接口卡)的命令,英文全称是network interfaces configuring

1、ifconfig -a

[root@test1 yum.repos.d]# ifconfig -a

eth0    Link encap:Ethernet  HWaddr 00:0C:29:1F:06:D4

     inet addr:192.168.1.108  Bcast:192.168.1.255  Mask:255.255.255.0

     inet6 addr: fe80::20c:29ff:fe1f:6d4/64 Scope:Link

     UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

     collisions:0 txqueuelen:1000

     RX bytes:29699855 (28.3 MiB)  TX bytes:5637694 (5.3 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:184 errors:0 dropped:0 overruns:0 frame:0

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

     collisions:0 txqueuelen:0

     RX bytes:12878 (12.5 KiB)  TX bytes:12878 (12.5 KiB)

[root@test1 yum.repos.d]#

通过这个命令可以看到网卡的ip地址和mac地址,还可以看到lo回环地址。

第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)

第二行:网卡的IP地址、子网、掩码

第三行:UP(代表网卡开启状态)RUNNING(代表网卡的网线被接上)MULTICAST(支持组播)MTU:1500(大传输单元):1500字节

第四、五行:接收、发送数据包情况统计

第七行:接收、发送数据字节数统计信息。

2、ifconfig interface [up|down]  //启动接口或禁用接口

3、ifconfig interface IP/mask  //为接口设置ip地址

4、ifconfig interface-alias IP/mask  //为接口别名设置ip地址;立即生效

二、route

查看:route -n

添加:route add

route add  [-net|-host]  target [netmask Nm] [gw Gw] [[dev] If]

目标:192.168.1.3  网关:172.16.0.1

~]# route add -host 192.168.1.3 gw 172.16.0.1 dev eth0

目标:192.168.0.0 网关:172.16.0.1

~]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0

~]# route add -net 192.168.0.0/24 gw 172.16.0.1 dev eth0

默认路由,网关:172.16.0.1

~]# route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.0.1

~]# route add default gw 172.16.0.1

删除:route del

route del [-net|-host] target [gw Gw] [netmask Nm] [[dev] If]

目标:192.168.1.3  网关:172.16.0.1

~]# route del -host 192.168.1.3

目标:192.168.0.0 网关:172.16.0.1

~]# route del -net 192.168.0.0 netmask 255.255.255.0

三、netstat

netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

显示网络连接:

netstat [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e[--extend|-e]]  [--program|-p]

-t: tcp协议相关

-u: udp协议相关

-w: raw socket相关

-l: 处于监听状态

-a: 所有状态

-n: 以数字显示IP和端口;

-e:扩展格式

-p: 显示相关进程及PID

常用组合:

-tan, -uan, -tnl, -unl

显示路由表:

netstat  {--route|-r} [--numeric|-n]

-r: 显示内核路由表

-n: 数字格式

显示接口统计数据:

netstat  {--interfaces|-I|-i} [iface] [--all|-a] [--extend|-e] [--program|-p] [--numeric|-n]

# netstat -i

# netstat -I IFACE

四、ip

Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者

ip - show / manipulate routing, devices, policy routing and tunnels

ip [ OPTIONS ] OBJECT { COMMAND | help }

OBJECT := { link | addr | route }

link OBJECT:

ip link - network device configuration

set

dev IFACE

可设置属性:

up and down:激活或禁用指定接口;

show

[dev IFACE]:指定接口

[up]:仅显示处于激活状态的接口

ip address - protocol address management

ip addr { add | del } IFADDR dev STRING

[label LABEL]:添加地址时指明网卡别名

[scope {global|link|host}]:指明作用域

global: 全局可用;

link: 仅链接可用;

host: 本机可用;

[broadcast ADDRESS]:指明广播地址

ip address show - look at protocol addresses

[dev DEVICE]

[label PATTERN]

[primary and secondary]

ip address flush - flush protocol addresses

使用格式同show

ip route - routing table management

ip route add

添加路由:ip route add TARGET via GW dev IFACE src SOURCE_IP

TARGET:

主机路由:IP

网络路由:NETWORK/MASK

添加网关:ip route add defalt via GW dev IFACE

ip route delete

删除路由:ip route del TARGET

ip route show

ip route flush

[dev IFACE]

[via PREFIX]

五、ss

ss是Socket Statistics的缩写。顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容。但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快速更高效。

格式:ss [OPTION]... [FILTER]

选项:

-t: tcp协议相关

-u: udp协议相关

-w: 裸套接字相关

-x:unix sock相关

-l: listen状态的连接

-a: 所有

-n: 数字格式

-p: 相关的程序及PID

-e: 扩展的信息

-m:内存用量

-o:计时器信息

运行结果一目了然,而且速度很快

[root@test1 yum.repos.d]# ss -tanlp

State    Recv-Q Send-Q                                            Local Address:Port                                             Peer Address:Port

LISTEN    0    128                                                   :::22                                                   :::*    users:(("sshd",1813,4))

LISTEN    0    128                                                   *:22                                                   *:*    users:(("sshd",1813,3))

LISTEN    0    128                                                   :::40470                                                 :::*    users:(("rpc.statd",1635,11))

LISTEN    0    128                                               127.0.0.1:631                                                   *:*    users:(("cupsd",1673,7))

LISTEN    0    128                                                  ::1:631                                                  :::*    users:(("cupsd",1673,6))

LISTEN    0    100                                                  ::1:25                                                   :::*    users:(("master",1990,13))

LISTEN    0    100                                               127.0.0.1:25                                                   *:*    users:(("master",1990,12))

LISTEN    0    128                                                   :::58524                                                 :::*    users:(("rpc.mountd",3684,14))

LISTEN    0    64                                                   :::2049                                                  :::*

LISTEN    0    64                                                    *:2049                                                  *:*

LISTEN    0    128                                                   :::45697                                                 :::*    users:(("rpc.mountd",3684,18))

LISTEN    0    64                                                    *:42242                                                  *:*

LISTEN    0    128                                                   *:44843                                                  *:*    users:(("rpc.mountd",3684,16))

LISTEN    0    128                                                   *:875                                                   *:*    users:(("rpc.rquotad",3679,4))

LISTEN    0    128                                                   *:55244                                                  *:*    users:(("rpc.mountd",3684,8))

LISTEN    0    64                                                   :::59629                                                 :::*

LISTEN    0    128                                                   *:33549                                                  *:*    users:(("rpc.mountd",3684,12))

LISTEN    0    128                                                   *:53679                                                  *:*    users:(("rpc.statd",1635,9))

LISTEN    0    128                                                   :::111                                                  :::*    users:(("rpcbind",1517,11))

LISTEN    0    128                                                   *:111                                                   *:*    users:(("rpcbind",1517,8))

LISTEN    0    128                                                   :::42480                                                 :::*    users:(("rpc.mountd",3684,10))

[root@test1 yum.repos.d]#

六、nmcli

nmcli  [ OPTIONS ] OBJECT { COMMAND | help }

device - show and manage network interfaces

connection - start, stop, and manage network connections

如何修改IP地址等属性:

#nmcli connection modify IFACE [+|-]setting.property value

setting.property:

ipv4.addresses

ipv4.gateway

ipv4.dns1

ipv4.method

manual

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:Linux网络管理工具-创新互联
URL标题:http://kswjz.com/article/ghcpg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流