在本文中,我们将详细介绍centos7如何配置网络、网卡、ip命令的各个方面,并为您提供关于centos7配置网卡ip地址的相关解答,同时,我们也将为您带来关于CentOS6升级到CentOS7、Ce
在本文中,我们将详细介绍centos 7如何配置网络、网卡、ip命令的各个方面,并为您提供关于centos7配置网卡ip地址的相关解答,同时,我们也将为您带来关于CentOS 6 升级到 CentOS 7、CentOS 6 和 CentOS 7 防火墙的关闭、CentOS 6, CentOS 7 安装mysql数据库、CentOS 6.6 系统升级到 CentOS 6.7的有用知识。
本文目录一览:- centos 7如何配置网络、网卡、ip命令(centos7配置网卡ip地址)
- CentOS 6 升级到 CentOS 7
- CentOS 6 和 CentOS 7 防火墙的关闭
- CentOS 6, CentOS 7 安装mysql数据库
- CentOS 6.6 系统升级到 CentOS 6.7
centos 7如何配置网络、网卡、ip命令(centos7配置网卡ip地址)
Linux网络相关配置文件
Linux网络配置相关的文件根据不同的发行版目录名称有所不同,但大同小异,主要有似下目录或文件。
(1)/etc/hostname:主要功能在于修改主机名称。
(2)/etc/sysconfig/network-scrips/ifcfg-enoN:是设置网卡参数的文件,比如IP地址、子网掩码、网关等,N为一串数字。
(3)/etc/resolv.conf:此文件设置了DNS相关的信息,用于将域名解析到IP。
(4)/etc/hosts:计算机的IP对应的主机名称或域名对应的IP地址,通过设置/etc/nsswitch.conf中的选项可以选择是DNS解析优先还是本地设置优先。
(5)/etc/nsswitch.conf(name service switch configuration,名字服务切换配置):规定通过哪些途径,以及按照什么顺序通过这些途径来查找特定类型的信息。
配置网络
ifconfig命令可以用于查看、配置、启用或禁用指定网络接口,如配置网卡的IP地址、掩码、广播地址、网关等,Windows类似的命令为ipconfig。
语法如下:#ifconfig interface [[-net -host] address [parameters]]
其中inteface是网络接口名,address是分配给指定接口的主机名或IP地址。-net和-host参数分别告诉ifconfig将这个地址作为网络号或是主机地址。与之前版本的网卡命名规则不同,CentOS 7 采用固件信息、网络拓扑等信息来命名网卡,这种方法更易于固定网卡的名称。Linux系统中的网卡lo为本地环回接口,IP地址固定为127.0.0.1,子网掩码8位,表示本机。
ifconfig常见使用方法如下:
#查看网卡基本信息 [[email protected] ~]# ifconfig
#命令后面可接网络接口用于查看指定网络接口的信息 [[email protected] ~]# ifconfig eno16777736 eth016777736 fiags=4163<UP,broADCAST,RUNNING,MULTICAST> mtu 1500 inet addr:192.168.111.136 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fec2:14a8/64 Scope:Link ether00:0c:29:0b:07:76 txqueuelen1000 RX packets 851 boytes 75229 (73.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 561 bytes 100225 (97.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
说明:
第1行:UP表示此网络接口为启动状态,RUNNING表示网卡设备已连接,MULTICAST表示支持持组播,MTU为数据包最大传输单元。
第2行:依次为网卡IP、子网掩码、广播地址。
第3行:ipv6地址。
第4行:Ethernet(以太网)表示连接类型,ether为网卡的MAC地址。
第5行:接收数据包个数、大小统计信息。
第6行:异常接收包的数量,如丢包量,错误等。
第7行:发送数据包个数、大小统计信息。
第8行:异常发送包数量,如丢包量,错误等。
如果第6行和第8行中的丢包量、错误包量较高,通常表示物理链路存在问题。咧如网线干扰过大、距离太长等。
设置IP地址使用以下命令
#设置网卡IP地址 [[email protected] ~]# ifconfig eno16777736:1 192.168.100.100 netmask 255.255.255.0 up
设置完后使用ifconifg命令查看,可以看到两个网卡信息了,分别为:eth0和eth1。如继续设置其他IP,可以使用类似的方法。
#更改网卡的MAC地址 [[email protected] ~]# ifconfig eno16777736:1 hw ether 00:0c:29:0b:07:77 [[email protected] ~]# ifconfig eno16777736:1 | grep ether
#将某个网络接口禁用 #使用另一种形式表示子网掩码 [[email protected] ~]# ifconfig eno16777736:1 192.168.100.170、24 up [[email protected] ~]# ifconfig eno16777736:1 down [[email protected] ~]# ifconfig
除以上功能外,ifconfig还可以设置网卡的MTU。以上的设置会在重启后丢失,如需重启后依然生效,可以通过设置网络接口文件永久生效。
提示:在CentOS和RHEL中使用命令ifup和ifdown加网络接口名,可以启用、禁用对应的网络接口。
配置Linux系统的IP地址
要配置主机IP地址,可以直接通过终端命令设置,如想设置在系统重启后依然生效,可以通过设置对应的网络接口文件。
[[email protected] network-scripts]#cat ifcfg-eno33554984 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=eno16777736 UUID=ae0965e7-22b9-45aa-8ec9-3f0a20a85d11 ONBOOT=yes #开启自动启用网络连接 IPADDR0=192.168.21.128 #设置IP地址 PREFIXO0=255.255.255.224 #设置子网掩码 GATEWAY0=192.168.21.2 #设置网关 DNS1=8.8.8.8 #设置主DNS DNS2=8.8.4.4 #设置备DNS
网卡设置参数说明
参数 | 说明 |
TYPE | 设备连接类型,此处为以太网 |
BOOTPROTO | 使用动态IP 还是静态IP |
IPADDR0 | 第一IP地址 |
PREFIX0 | 第一IP地址对应的子网掩码长度 |
GATEWAY0 | 第一IP地址对应的网关 |
DNS1和DNS2 | DNS服务器地址 |
DEFROUTE | 是否为默认路由 |
ONBOOT | 系统启动时是否设置此网络接口 |
NAME | 设备名,此处对应网络接口为eno33554984 |
设置完ifcfg-eth0文件后,需要重启网络服务才能生效,重启后使用ifconfig查看设置是否生效:
[[email protected] network-scripts]# service network restart
同一个网络接口可以使用子接口的方式设置多个IP地址
[[email protected] ~]# ifconfig eno33554984:2 192.168.146.152 netmask 255.255.255.0 up
当服务器重启或网络服务重启后,子接口配置将消失,如需重启后依然生效,可以将配置子接口命令加入/etc/rc.local文件中。
设置主机名
[[email protected] network-scripts]# hostname www.wanyunshuju.com
如需修改重启后依然生效,可以将主机名写入文件/etc/hostname中。
[[email protected] ~]# hostname www.wanyunshuju.com
设置默认网关
(1)第1种方法就是直接使用route命令,在设置默认网关之前,先用route -n命令查看路由表。执行如下命令设置网关。
[[email protected] /]# route add default gw 192.168.1.254
如果不想每次开机都执行route命令,则应该把要执行的命令写入/etc/rc.d/rc.local文件中。
(2)第2种方法是在/etc/sysconfig/network-scripts/ifcfg-接口文件添加如下字段:
GATEWAY=192.168.10.254
同样,只要是更改了脚本文件,必须重启网络服务来使设置生效,可执行下面的命令:
[[email protected] /]# service network restart
设置DNS服务器
设置DNS服务器需修改/etc/resolv.conf文件即可。下面是一个resolv.conf文件。
[[email protected] ~]# cat /etc/resolv.conf nameserver 192.168.3.1 nameserver 192.168.3.2 options rotate options timeout:1 attempts:2
原文地址:https://idc.wanyunshuju.com/li/20.html,另外有些版本已经没有"ifconfig"指令了
CentOS 6 升级到 CentOS 7
注意
非必要情况,请使用重新安装系统的方式升级,原因如下:
- 并非所有的系统都能顺利从 6 升级到 7,安装的软件越少,升级成功的可能性越大;
- 只支持 6.5 及以上系统升级到不高于 7.2 系统;
- 升级的耗时完全不比重新安装少,绝大多数情况下会耗费更长的时间和更多精力;
- 升级完成后处理各种依赖是一个非常头大的问题。
本人在同一天升级了两台电脑,一个成功一个失败。成功的那台电脑额外花了一天时间处理各种依赖和问题,失败的电脑半小时装好系统和必备软件,用得爽歪歪。所以如非必要,建议采用备份数据后直接重装系统的方式。
操作
通过软件方式从 6 升级到 7,请参考下面的步骤:
-
升级当前系统到最新版本:
yum update -y
-
安装旧版
openscap
:yum remove -y openscap && yum install -y http://dev.centos.org/centos/6/upg/x86_64/Packages/openscap-1.0.8-1.0.1.el6.centos.x86_64.rpm
; -
添加
upgradetool
源:cat <<EOF >/etc/yum.repos.d/upgradetool.repo [upgrade] name=CentOS-$releasever - Upgrade Tool baseurl=http://dev.centos.org/centos/6/upg/x86_64/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 EOF
-
安装升级工具:
yum install -y redhat-upgrade-tool preupgrade-assistant preupgrade-assistant-contents
; -
执行升级可行性分析:
preupg -l
,该命令会耗费几分钟到几十分钟时间。如果出现preupg: error: [Errno 2] No such file or directory: ''/root/preupgrade/result.html''
的错误,请参考第一步安装openscap
的旧版; -
使用清华大学的
centos-vault
源安装 7.2 版本:centos-upgrade-tool-cli --network 7 --instrepo=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.2.1511/os/x86_64/
。** 注意:**7.2 是支持升级的最高版本,升级其他版本将会出现
Downloading failed: invalid data in .treeinfo: No section: ''checksums''
的错误提示; -
如果升级成功,用
reboot
命令重启系统;如果提示The requested URL returned error: 404 Not Found
等错误,基本上说明当前系统不支持直接升级。果断采用重装系统的正道吧,少年! -
系统重启后,有可能因为依赖库确实导致
ssh
无法启动,grep
不能正常使用等问题。基本功底够好的手动排查,然后一个个问题解决;搞不懂错误原因或者觉得处理麻烦的,备份数据后重装系统吧! -
使用
rpm -qa | grep el6
查看系统上残留的软件包。如果能手动清理掉,让系统update
无障碍,耐心一个个处理掉。如果觉得依赖太麻烦或者搞不定,备份数据后重装系统吧!
参考
- https://blog.51cto.com/moerjinrong/2340656
CentOS 6 和 CentOS 7 防火墙的关闭
CentOS6.5 查看防火墙的状态:
[linuxidc@localhost ~]$service iptable status 显示结果: [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service
● iptable.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead) -- 表示防火墙已经关闭 CentOS 6.5 关闭防火墙
[root@localhost ~]#servcie iptables stop -- 临时关闭防火墙 [root@localhost ~]#chkconfig iptables off -- 永久关闭防火墙
CentOS 7.2 关闭防火墙
CentOS 7.0 默认使用的是 firewall 作为防火墙,这里改为 iptables 防火墙步骤。 firewall-cmd --state #查看默认防火墙状态(关闭后显示 notrunning,开启后显示 running)
[root@localhost ~]#firewall-cmd --state not running 检查防火墙的状态:
从 centos7 开始使用 systemctl 来管理服务和程序,包括了 service 和 chkconfig。
[root@localhost ~]#systemctl list-unit-files|grep firewalld.service -- 防火墙处于关闭状态 firewalld.service disabled 或者
[root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) 关闭防火墙:
systemctl stop firewalld.service #停止 firewall systemctl disable firewalld.service #禁止 firewall 开机启动
[root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service
启动一个服务:systemctl start firewalld.service 关闭一个服务:systemctl stop firewalld.service 重启一个服务:systemctl restart firewalld.service 显示一个服务的状态:systemctl status firewalld.service 在开机时启用一个服务:systemctl enable firewalld.service 在开机时禁用一个服务:systemctl disable firewalld.service 查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $? 查看已启动的服务列表:systemctl list-unit-files|grep enabled Centos 7 firewall 命令: 查看已经开放的端口:
firewall-cmd --list-ports 开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent 命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口 / 通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启 firewall systemctl stop firewalld.service #停止 firewall systemctl disable firewalld.service #禁止 firewall 开机启动 firewall-cmd --state #查看默认防火墙状态(关闭后显示 notrunning,开启后显示 running) CentOS 7 以下版本 iptables 命令 如要开放 80,22,8080 端口,输入以下命令即可
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT 然后保存:
/etc/rc.d/init.d/iptables save 查看打开的端口:
/etc/init.d/iptables status 关闭防火墙 1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
查看防火墙状态: service iptables status
下面说下 CentOS7 和 6 的默认防火墙的区别
CentOS 7 默认使用的是 firewall 作为防火墙,使用 iptables 必须重新设置一下
1、直接关闭防火墙
systemctl stop firewalld.service #停止 firewall
systemctl disable firewalld.service #禁止 firewall 开机启动
2、设置 iptables service
yum -y install iptables-services
如果要修改防火墙配置,如增加防火墙端口 3306
vi /etc/sysconfig/iptables
增加规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存退出后
systemctl restart iptables.service #重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
最后重启系统使设置生效即可。
systemctl start iptables.service #打开防火墙
systemctl stop iptables.service #关闭防火墙
解决主机不能访问虚拟机 CentOS 中的站点 前阵子在虚拟机上装好了 CentOS6.2,并配好了 apache+php+mysql,但是本机就是无法访问。一直就没去折腾了。
具体情况如下
- 本机能 ping 通虚拟机
- 虚拟机也能 ping 通本机 3. 虚拟机能访问自己的 web 4. 本机无法访问虚拟机的 web
后来发现是防火墙将 80 端口屏蔽了的缘故。
检查是不是服务器的 80 端口被防火墙堵了,可以通过命令:telnet server_ip 80 来测试。
解决方法如下: /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 然后保存: /etc/rc.d/init.d/iptables save 重启防火墙 /etc/init.d/iptables restart
CentOS 防火墙的关闭,关闭其服务即可: 查看 CentOS 防火墙信息:/etc/init.d/iptables status 关闭 CentOS 防火墙服务:/etc/init.d/iptables stop
CentOS 6, CentOS 7 安装mysql数据库
#!/bin/sh
# CentOs 6
#使用sohu镜像,速度快
wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-server-5.6.35-1.el6.x86_64.rpm
wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-client-5.6.35-1.el6.x86_64.rpm
wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-shared-5.6.35-1.el6.x86_64.rpm
#删除默认安装包
rpm -qa| grep mysql-libs | xargs rpm -e --nodeps
#安装依赖包
yum -y install numactl
rpm -ivh MySQL-shared-5.6.35-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.35-1.el6.x86_64.rpm
rpm -ivh MySQL-server-5.6.35-1.el6.x86_64.rpm
#获取默认root密码
sqlpasswd=`cat /root/.mysql_secret | awk -F''): '' {''print $2''}`
echo "MySQL root passwd: $sqlpasswd"
#设置数据库服务端编码为utf8
echo character_set_server=utf8 >> /usr/my.cnf
#重启数据库
service mysql restart
#!/bin/sh
# CentOS 7
wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-server-5.6.35-1.el7.x86_64.rpm
wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-client-5.6.35-1.el7.x86_64.rpm
wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-shared-5.6.35-1.el7.x86_64.rpm
rpm -ivh MySQL-shared-5.6.35-1.el7.x86_64.rpm
rpm -ivh MySQL-client-5.6.35-1.el7.x86_64.rpm
rpm -ivh MySQL-server-5.6.35-1.el7.x86_64.rpm
#获取默认root密码
sqlpasswd=`cat /root/.mysql_secret | awk -F''): '' {''print $2''}`
echo "MySQL root passwd: $sqlpasswd"
#设置数据库服务端编码为utf8
echo character_set_server=utf8 >> /usr/my.cnf
SET PASSWORD FOR ''root''@''localhost''=PASSWORD(''newpass'');
CentOS 6.6 系统升级到 CentOS 6.7
1、利用 Centos6.7 ISO 镜像挂载为本地镜像
创建一个挂载目录 CentOS 6.6 系统升级到 CentOS 6.7
mkdir /mnt/data
2、挂载镜像(远程镜像)
mount -t nfs 172.16.2.100://iso /mnt/data
3、yum 源配置文件
vim CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/data
gpgcheck=1
enabled=1
gpgkey=file:///mnt/data/RPM-GPG-KEY-CentOS-6
4、清除 yum 缓存进行更新
yum clean all
yum makecache
5、系统更新:
yum -y update
(如有报错看依赖进行安装,或者依赖版本问题需要重新安装)
rpm -e kernel-2.6.32-504.el6.x86_64
rpm -e kernel-devel-2.6.32-504.el6.x86_64
重启:
reboot
可能会遇到的依赖提示:
rpm -e libreport
yum remove libreport
yum -y install libreport
yum remove libreport-filesystem
yum -y install libreport
我们今天的关于centos 7如何配置网络、网卡、ip命令和centos7配置网卡ip地址的分享已经告一段落,感谢您的关注,如果您想了解更多关于CentOS 6 升级到 CentOS 7、CentOS 6 和 CentOS 7 防火墙的关闭、CentOS 6, CentOS 7 安装mysql数据库、CentOS 6.6 系统升级到 CentOS 6.7的相关信息,请在本站查询。
本文标签: