export
设置变量
export test=/home/lgb
export PATH=$PATH:/usr/local/mysql/bin
export -p
unset
清除环境变量
unset test
场景:比如你需要安全oracle这个数据库或者说安装JAVA相关的软件时,你需要导入环境变量路径,那么需要这个命令
[root@localhost tmp]# export test=/home
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# echo $test
/home
[root@localhost tmp]# unset test
[root@localhost tmp]# echo $test
[root@localhost tmp]#
chkconfig
管理服务软件自启
chkconfig --level 35 mysqld on
chkconfig --list
场景:有时候,我们需要开机自动重启程序。
[root@localhost tmp]# chkconfig --level 35 NetworkManager
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 35 sshd
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# systemctl enable sshd
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 35 network
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]# chkconfig --level 135 network
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]# chkconfig --level 1 network
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 3 network
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 35 network
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]# chkconfig --level 3 5 network
chkconfig version 1.3.61 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: chkconfig [--list] [--type <type>] [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig --override <name>
chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>
[root@localhost tmp]# chkconfig --level 5 network
[root@localhost tmp]#
[root@localhost tmp]#
runlevel
显示系统当前运行级别
runlevel
[root@localhost tmp]# runlevel
N 3
[root@localhost tmp]#
getenforce
查看selinux的运行状态
getenforce
它这个属于系统级别的安全
场景:有时候我们一些服务无法使用,比如我们的FTP,所以作为初学者,我们需要去关闭selinux。
[root@localhost tmp]# getenforce
Enforcing
[root@localhost tmp]#
从上面可知selinux是开启的,那么需要去关闭掉,否则会对初学者易用性太差。
setenforce
关闭或者开启selinux
开启后,导致文件权限修改不了等问题,下面就是关闭设置setlinux的方法
[root@localhost tmp]# getenforce
Enforcing
[root@localhost tmp]# setenforce 0
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# getenforce
Permissive
[root@localhost tmp]#
init
修改系统运行级别
重启系统:Init 6、关闭系统:init 0
我建议用这个命令进行开关机,因为它代表了系统运行级别的内容。
service
管理服务
service httpd start
[root@localhost tmp]# service sshd start
Redirecting to /bin/systemctl start sshd.service
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]#
netstat
查看服务端口
netstat -anp
netstat -apn |grep 8080
场景:我们经常安装一些网络程序,有时候会查看看端口号及状态,特别有用。
route
查看路由表
Route -n
[root@localhost cdrom]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.92.0 0.0.0.0 255.255.255.0 U 100 0 0 eno16777736
[root@localhost cdrom]#
ifdown
关闭指定网卡
Ifdown lo
ifup
启动指定网卡
Ifup lo
Ifconfig
查看网卡参数
Ifconfig
[root@localhost cdrom]# ip addre
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fe:83:2f brd ff:ff:ff:ff:ff:ff
inet 192.168.92.128/24 brd 192.168.92.255 scope global dynamic eno16777736
valid_lft 1375sec preferred_lft 1375sec
inet6 fe80::20c:29ff:fefe:832f/64 scope link
valid_lft forever preferred_lft forever
[root@localhost cdrom]# ifdown lo
Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
[root@localhost cdrom]# ca /etc/sysconfig/network-scripts/
-bash: ca: command not found
[root@localhost cdrom]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-default ifcfg-static ifdown-bnep ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifcfg-eno16777736 ifcfg-test1 ifdown-eth ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global
ifcfg-lo ifdown ifdown-ib ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ib ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]# cat ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
[root@localhost network-scripts]# systemctl stop NetworkManager
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]# ifdown lo
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]# cat ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
[root@localhost network-scripts]# systemctl stop NetworkManager
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]# ifdown lo
[root@localhost network-scripts]#
[root@localhost network-scripts]#
[root@localhost network-scripts]# ip add
1: lo: <LOOPBACK> mtu 65536 qdisc noqueue state DOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fe:83:2f brd ff:ff:ff:ff:ff:ff
inet 192.168.92.128/24 brd 192.168.92.255 scope global dynamic eno16777736
valid_lft 1243sec preferred_lft 1243sec
inet6 fe80::20c:29ff:fefe:832f/64 scope link
valid_lft forever preferred_lft forever
[root@localhost network-scripts]# ifup lo
[root@localhost network-scripts]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:fe:83:2f brd ff:ff:ff:ff:ff:ff
inet 192.168.92.128/24 brd 192.168.92.255 scope global dynamic eno16777736
valid_lft 1223sec preferred_lft 1223sec
inet6 fe80::20c:29ff:fefe:832f/64 scope link
ping
测试网络连通性
ping 192.168.3.254
telnet
远程登录命令,可以测试另外一台服务器的某个端口是否打开
telnet命令 192.168.3.27 22