软件管理 基础配置(运维笔记)
软件管理 基础配置(运维笔记)
配置IP地址
这里以CentOS为例
进入系统网络设置目录:
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ #进入目录
[root@localhost network-scripts]# ls #查看配置文件
ifcfg-ens33 ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functions
ifcfg-lo ifdown-isdn ifdown-tunnel ifup-ipv6 ifup-sit network-functions-ipv6
ifdown ifdown-post ifup ifup-isdn ifup-Team
ifdown-bnep ifdown-ppp ifup-aliases ifup-plip ifup-TeamPort
ifdown-eth ifdown-routes ifup-bnep ifup-plusb ifup-tunnel
ifdown-ib ifdown-sit ifup-eth ifup-post ifup-wireless
ifdown-ippp ifdown-Team ifup-ib ifup-ppp init.ipv6-global
查看默认网关:
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.126.2 0.0.0.0 UG 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.126.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
Gateway下的192.168.126.2就是默认网关
设置静态IP:
进入ens33网卡配置文件
[root@localhost network-scripts]# vi ifcfg-ens33
使用NAT模式配置网络,根据生成的IP地址和上述命令查看网关,编辑:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #设置静态模式
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=ens33
UUID=6c9cafc0-eb4f-40ca-b7b1-630547eadd40
DEVICE=ens33 #设备名称
ONBOOT=yes #开机是否激活网卡
IPADDR=192.168.126.129 #IP地址 你自己虚拟机的IP地址
NETMASK=255.255.255.0 #掩码
GATEWAY=192.168.126.2 #网关
重启网络服务
添加网卡
添加一张网卡,需要一个封闭的网络环境,选择仅主机模式
进入VMware,步骤:
上方选项 虚拟机->网络适配器->下方添加->网络适配器->仅主机模式
仅主机模式通过网络适配器VMnet1连接,打开其IPV4属性,如果自动获取的话,IP地址默认为10.1.1.1
我们将虚拟网卡地址设置为10.1.1.254
子网掩码:255.255.255.0
查看网卡信息:
[root@localhost network-scripts]# ifconfig -a
发现多了一张网卡ens36即为仅主机模式下网卡
新建ens36配置文件
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36
编辑ens-36配置文件:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
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=ens33
UUID=6c9cafc0-eb4f-40ca-b7b1-630547eadd40
DEVICE=ens36 #设备名称
ONBOOT=yes #开机是否激活网卡
IPADDR=10.1.1.250 #IP地址 随便写 只要不与vmnet1配置相同即可
NETMASK=255.255.255.0 #掩码
重启网络:
[root@localhost network-scripts]# service network restart Restarting network (via systemctl):
[ 确定 ]
测试网络环境:
#外网ping通
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (180.101.50.188) 56(84) bytes of data.
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=1 ttl=128 time=632 ms
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=2 ttl=128 time=595 ms
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=3 ttl=128 time=194 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2234ms
rtt min/avg/max/mdev = 194.210/473.872/632.320/198.334 ms
#内网vmnet1 ping通
[root@localhost network-scripts]# ping 10.1.1.254
PING 10.1.1.254 (10.1.1.254) 56(84) bytes of data.
64 bytes from 10.1.1.254: icmp_seq=1 ttl=128 time=0.880 ms
64 bytes from 10.1.1.254: icmp_seq=2 ttl=128 time=1.35 ms
64 bytes from 10.1.1.254: icmp_seq=3 ttl=128 time=1.97 ms
64 bytes from 10.1.1.254: icmp_seq=4 ttl=128 time=1.64 ms
^C
修改主机名
[root@localhost ~]# vi /etc/sysconfig/network
[root@localhost ~]# cat /etc/sysconfig/network
# Created by anaconda
HOSTNAME=RKUN18 #自己任意设定
退出重新登录生效
绑定主机名与IP地址
# vi /etc/hosts
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.126.129 RKUN18
10.1.1.250 RKUN18
防火墙与SELinux关闭
临时关闭防火墙,方便服务搭建:
[root@localhost ~]# systemctl stop firewalld.service
永久关闭防火墙:
[root@localhost ~]# systemctl disable firewalld.service
关闭SELinux
临时关闭:
[root@localhost ~]# setenforce 0
设置始终关闭:
[root@localhost ~]# vi /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted