環境說明:CentOS7 最小安裝,全部配置默認
安裝完成後,設置一個臨時IP地址,方便SSH鏈接進行配置linux
查看服務器接口
ios
ip link
查看是否有IP地址
vim
ip addr
設置接口UP
centos
ip link set eno16777728 up
設置一個臨時IP
bash
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.查看時間設置
dom
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.設置時區
查看能夠設置的時區
ide
timedatectl list-timezones | grep Asia
設置時區爲上海
oop
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
設置完成