环境说明:CentOS7 最小安装,所有配置默认
安装完成后,设置一个临时IP地址,方便SSH连接进行配置
查看服务器接口
ip link
查看是否有IP地址
ip addr
设置接口UP
ip link set eno16777728 up
设置一个临时IP
ip addr add 10.10.10.71/24 dev eno16777728
添加网关
ip route add default via 10.10.10.2 dev eno16777728
添加DNS
vi /etc/resolv.conf nameserver 119.29.29.29
一.设置时区和时间
1.查看时间设置
timedatectl Local time: Sat 2016-07-02 12:44:43 EDT #服务器时间 Universal time: Sat 2016-07-02 16:44:43 UTC #标准时间(时区0时间) RTC time: Sat 2016-07-02 16:44:43 #硬件时间 Time zone: America/New_York (EDT, -0400) #时区 NTP enabled: n/a NTP synchronized: no RTC in local TZ: no DST active: yes Last DST change: DST began at Sun 2016-03-13 01:59:59 EST Sun 2016-03-13 03:00:00 EDT Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2016-11-06 01:59:59 EDT Sun 2016-11-06 01:00:00 EST
2.设置时区
查看可以设置的时区
timedatectl list-timezones | grep Asia
设置时区为上海
timedatectl set-timezone Asia/Shanghai
3.同步网络时间并将时间写入到bios
yum install ntpdate -y ntpdate 0.asia.pool.ntp.org timedatectl set-local-rtc 1 #将硬件时钟调整为与本地时钟一致(将BIOS时间改为和系统时间一至)
4.验证时间是否正确
timedatectl Local time: Sat 2016-07-02 16:05:24 CST Universal time: Sat 2016-07-02 08:05:24 UTC RTC time: Sat 2016-07-02 16:05:24 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: n/a NTP synchronized: no RTC in local TZ: yes DST active: n/a
二.关闭selinux,firewalld和NetworkManager
vi /etc/selinux/config
修改SELINUX=enforcing为SELINUX=disabled
或者
sed -i ‘s/SELINUX=.*/SELINUX=disabled/‘ /etc/selinux/config
关闭并停止防火墙
systemctl stop firewalld systemctl disable firewalld
关闭并停止NetworkManager
systemctl stop NetworkManager systemctl disable NetworkManager
三.修改计算机名
hostnamectl set-hostname localhost.localdomain
或者
vi /etc/hostname localhost.localdomain
四.修改网卡接口名
1.修改grub,编辑/etc/default/grub并加入“net.ifnames=0”到GRUB_CMDLINE_LINUX变量
vi /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed ‘s, release .*$,,g‘ /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 rhgb quiet" GRUB_DISABLE_RECOVERY="true" grub2-mkconfig -o /boot/grub2/grub.cfg
2.手动生成70-persistent-net.rules
查看接口的MAC地址
ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:28:ac:54 brd ff:ff:ff:ff:ff:ff
mac地址为00:0c:29:28:ac:54 , 将MAC地址填入文件70-persistent-net.rules
vi /etc/udev/rules.d/70-persistent-net.rules SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:28:ac:54", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
3.修改网卡配置文件
vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none IPADDR=10.10.10.71 PREFIX=24 GATEWAY=10.10.10.2 mv /etc/sysconfig/network-scripts/ifcfg-eno16777728 /etc/sysconfig/network-scripts/ifcfg-eno16777728.bak
4.重起服务器
reboot
五.安装vim 和网络管理组件ifconfig等
yum install net-tools bash-completion vim -y ifconfig route
设置完成
时间: 2024-12-20 15:58:50