The centos7 mini version has no network connection by default. We can view local ip information:
[ root@localhost ~]# ip addr
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: eno16777728:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ad:96:16 brd ff:ff:ff:ff:ff:ff
[ root@localhost ~]#
View network configuration files
[ root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777728
UUID=05d5a7d5-f16e-4492-9ea1-fa46b7134a8a
DEVICE=eth0
ONBOOT=no
[ root@localhost ~]#
If you want to enable DHCP
, update the ONBOOT
value of the ifcfg-
file from no
to yes
, save and restart the service.
[ root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
The result is as follows
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777728
UUID=05d5a7d5-f16e-4492-9ea1-fa46b7134a8a
DEVICE=eno16777728
ONBOOT=yes
Restart network service
[ root@localhost ~]# service network restart
Restarting network(via systemctl):[ OK ]
View ip information:
[ root@localhost ~]# ip addr
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: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ad:96:16 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.136/24 brd 172.16.1.255 scope global dynamic eno16777728
valid_lft 1626sec preferred_lft 1626sec
inet6 fe80::20c:29ff:fead:9616/64 scope link
valid_lft forever preferred_lft forever
If you have a fixed ip, you need to update ifcfg-eth0
and add static address IPADDR
.
[ root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777728
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777728
UUID=05d5a7d5-f16e-4492-9ea1-fa46b7134a8a
DEVICE=eno16777728
ONBOOT=yes
DNS1=172.16.1.21
DOMAIN=2factor.net
IPADDR=172.16.1.25
PREFIX=24
GATEWAY=172.16.1.254
Restart network service
[ root@localhost ~]# service network restart
Restarting network(via systemctl):[ OK ]
Reference: https://wiki.centos.org/FAQ/CentOS7#head-a21a9e454157700367c9b7e9ccb1ff9954bec881
CentOS7 has installed openssh-server
by default, if not, execute the installation command as follows;
yum install openssh-server -y
Edit ssh configuration file
[ root@centos-linux ~]# vim /etc/ssh/sshd_config
Open the following configuration:
Port 22
# AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
# The default requires explicit activation of protocol 1
Protocol 2
# RSAAuthentication yes
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
Restart the service
systemctl restart sshd.service
More help about ssh: https://wiki.centos.org/HowTos/Network/SecuringSSH
Edit the file /etc/sudoers
First increase the write permission of sudoers
file
chmod 777/etc/sudoers
Then edit this file
vi /etc/sudoers
Add relevant user information
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
devid ALL=(ALL) ALL
devid
is my username, just save the file.
Recommended Posts