五、网络命令
1、 ping
# ping -c 5 192.168.45.181 (ping ip五次)
2、 ifconfig
查看ip: ifconfig
ip add
ip addr
ifconfig ens33 (仅查看ens33的网卡信息)
临时修改ip
ifconfig ens33 192.168.45.181 netmask 255.255.255.0
网卡重启: (7版本): systemctl restart network
(6版本): service network restart
临时添加多个ip
ifconfig ens33:0 192.168.45.190 netmask 255.255.255.0 up
删除临时ip: ifconfig ens33 del 192.168.45.190
添加真实网卡:
(7版本) nmcli connection add con-name ens33 type ethernet ifname ens33
(6版本)原网卡文件复制之后再改
3、 w (查看哪些用户已登录)
[root@localhost ~]# w
00:09:51 up 13 days, 2:04, 1 user, load average: 0.07, 0.14, 0.13
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.2.56 23:27 7.00s 0.02s 0.00s w
tty(终端) tty1 本地终端
pts/0 本地虚拟、远程终端
-bash:shell类型的其中一个
第一行: 00:09:51 up 13 days, 2:04, 1 user, load average: 0.07, 0.14, 0.13
现在时间 运行时间 登录用户 1min、5min、15min前的平均负载
第二行:
user tty from lohin idle jcpu pcpu
用户 终端 来源 登录时间 闲置时间 所有进程 当前进程
4、 who (简化版w)
5、 last (列出登录系统的相关信息)
[root@localhost ~]# last
root pts/0 192.168.2.56 Wed Jun 12 23:27 still logged in
root pts/0 192.168.2.199 Wed Jun 12 18:06 - 19:14 (01:07)
root pts/0 192.168.2.199 Wed Jun 12 17:55 - 17:57 (00:02)
名 终端 ip 开始时间 持续时间
6、 lastlog (显示所有账户最后一次登录时间)
[root@localhost ~]# lastlog
用户名 端口 来自 最后登陆时间
root pts/0 192.168.2.56 三 6月 12 23:27:10 +0800 2024
bin **从未登录过**
daemon **从未登录过**
...
用户: root:超级用户,根用户,可以登录系统
user1:普通用户,可以登录系统
bin、sshd、apache:系统用户、或服务用户(不能登录系统,但占用资源)
7、 write (给在线的写信)
write root pts/3
ctrl+d 保存
8、 wall (对所有现在的广播)
wall 字符串
wall 回车 字符串 ctrl+d
9、 mail 发信、收信
10、netstat (查看连接状态)
常见端口:
| ftp | ssh | telnet | SMTP | DNS | TFTP | http | POP3 | SNMP | Mysql | Windwos终端 |
|---|---|---|---|---|---|---|---|---|---|---|
| 20、21 | 22 | 23 | 25 | 53 | 69 | 80 | 110 | 161 | 3306 | 3389 |
/etc/service (查看常见的端口)
netstat -tulm (查看本机所有监听的端口) (t,u,l.a.n.p)
-t (tcp协议)
-u (udp协议)
-l (监听)
-a (显示所有选项)
-n (以ip和端口形式显示信息)
-p (显示建立的相关信息程序名)