Centos7- 网络/Yum/SSH源配置

yum配置

  1. 配置yum源文件
1
vi /etc/yum.repos.d/CentOS-Base.repo
  1. 修改完成后执行:
1
2
3
yum clean all
rm -rf /var/cache/yum/
yum makecache
  1. 常用工具下载安装
1
yum install -y net-tools vim  unzip screen git wget lsof 

中科大(参考地址:http://mirrors.ustc.edu.cn/help/centos.html#)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

清华源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

网易源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

DNS配置

1.修改/etc/NetworkManager/NetworkManager.conf文件,在main部分添加 “dns=none” 选项

1
2
3
[main]
#plugins=ifcfg-rh,ibft
dns=none
  1. 执行sudo vi /etc/resolv.conf 配置DNS服务器。
1
2
3
4
nameserver 233.5.5.5  #阿里
nameserver 233.6.6.6
nameserver 8.8.8.8 #谷歌
nameserver 8.8.4.4

3.修改完成后执行systemctl restart NetworkManager.service重启网卡。

IP网关配置

1.编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #改成静态ip
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=f2ad7837-f291-49a9-9bae-b27df6ccd464
DEVICE=eth0
ONBOOT=yes #改为自动启动
IPADDR=192.168.0.197 #设置静态ip地址
NATMASK=255.255.255.0 #设置掩码
GETWAY=192.168.0.1 #设置网关

2.执行service network restart重启网络。

3.验证网络是否生效。

1
2
3
4
5
6
7
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from localhost (183.232.231.174): icmp_seq=1 ttl=52 time=26.8 ms
64 bytes from localhost (183.232.231.174): icmp_seq=2 ttl=52 time=23.9 ms
64 bytes from localhost (183.232.231.174): icmp_seq=3 ttl=52 time=24.6 ms
64 bytes from localhost (183.232.231.174): icmp_seq=4 ttl=52 time=26.4 ms
64 bytes from localhost (183.232.231.174): icmp_seq=5 ttl=52 time=23.9 ms

配置SSH

  1. 开启ssh服务需要root权限,先用root账户登陆。先检查有没有安装SSH服务
1
2
3
4
5
[root@localhost ~]# rpm -qa | grep ssh
openssh-clients-7.4p1-21.el7.x86_64 #ssh客户端
libssh2-1.8.0-3.el7.x86_64
openssh-7.4p1-21.el7.x86_64
openssh-server-7.4p1-21.el7.x86_64 #ssh服务端
  1. 如果没有安装ssh服务就安装 : yum install openssh-server -y
  2. 安装好后在ssh配置文件里进行配置 : vi /etc/ssh/sshd_config
1
2
3
4
5
6
7
8
Port 22 #开启22端口
#AddressFamily any
ListenAddress 0.0.0.0 #开启监听
ListenAddress ::


PermitRootLogin yes #如果使用root登录就配置yes,否则设置no
PubkeyAuthentication yes # 启用密钥对验证
  1. 修改完后用/bin/systemctl start sshd.service开启ssh服务,这个命令没有回显

  2. 开启后用ps -e | grep sshd检查一下ssh服务是否开启

1
2
3
[root@localhost ~]#  ps -e | grep sshd 
1082 ? 00:00:00 sshd
18694 ? 00:00:00 sshd
  1. 最后用netstat -an | grep 22检查一下22端口是否开启,开启之后使用SSH工具登录即可。
1
2
3
4
[root@localhost ~]# netstat -an | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 96 192.168.0.197:22 192.168.0.198:54142 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN

参考资料