Linux网络配置:CentOS7无法运行 ifconfig如何设置静态IP地址?

    1. CentOS7无法运行 ifconfig 的解决办法

    最近周末休息在家,在追兄弟连的 Linux 教程,在2.4章讲到配置 Linux CentOS 服务器IP地址的时候,就懵逼了,因为教程制作时间比较早,用的是 CentOS 6 演示的,所以产生了一些小问题,xerer安装的是 CentOS 7,内置程序已经没有 ifconfig 了。那么怎么办呢?xerer提供解决方案有两种。文章源自技术奇点-https://www.xerer.com/archives/32683.html

     文章源自技术奇点-https://www.xerer.com/archives/32683.html

    一般找不到 ifconfig 命令错误会显示:文章源自技术奇点-https://www.xerer.com/archives/32683.html

    1. -bash: ifconfig: command not found

    或者文章源自技术奇点-https://www.xerer.com/archives/32683.html

    1. -bash: /sbin/ifconfig: No such file or directory

    解决方法:文章源自技术奇点-https://www.xerer.com/archives/32683.html

    1. 替代命令 ip addr
    直接执行 ip addr 也可以显示网卡信息,另外 ip addr 添加/删除IP方法文章源自技术奇点-https://www.xerer.com/archives/32683.html

    1. ip addr add 192.168.0.200 dev ens33
    2. ip addr del 192.168.0.200 dev ens33

    add是添加,del是删除,最后的ens33是你网卡名文章源自技术奇点-https://www.xerer.com/archives/32683.html

    2. 重新安装 net-tools 包,让ifconfig命令复活文章源自技术奇点-https://www.xerer.com/archives/32683.html

    1. yum -y install net-tools

    不过命令虽然可以打出来,也可以配置IP,但是还是不能让 Linux 上网。这是因为没有配置DNS等信息造成的。请继续查看 CentOS7 配置静态IP地址 下面这一段文章。文章源自技术奇点-https://www.xerer.com/archives/32683.html

     文章源自技术奇点-https://www.xerer.com/archives/32683.html

    2. CentOS7 配置网络:

     文章源自技术奇点-https://www.xerer.com/archives/32683.html

    继上一章 CentOS 7 没有 ifconfig 的解决办法,兄弟连的 Linux 教程,在2.4章讲到配置 Linux CentOS 服务器IP地址的时候,就懵逼了,因为教程制作时间比较早,用的是 CentOS 6 演示的,很多已经不适用于最新版本的CentOS了,今天 xerer 给大家讲一下如何快速配置新版CentOS的IP地址。文章源自技术奇点-https://www.xerer.com/archives/32683.html

     文章源自技术奇点-https://www.xerer.com/archives/32683.html

    其实很简单,一句话就能解决的问题,首先 ip addr 查看自己的网卡名字,xerer 这里是 ens33文章源自技术奇点-https://www.xerer.com/archives/32683.html

    然后编辑 /etc/sysconfig/network-scripts/ifcfg-ens33 文件 (最后的这个ens33就是你的网卡名字)文章源自技术奇点-https://www.xerer.com/archives/32683.html

    vi /etc/sysconfig/network-scripts/ifcfg-ens33
    vi 编辑器的使用方法就不多讲了,功能太强大了,自己查一下,这里就告诉你简单的如何修改,按键盘 ‘i’ 键进入编辑模式,然后用方向键移动到最后一行,ONBOOT=no 那里,把no改成yes即可。然后按 ESC 键,再敲 :wq! 保存退出。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    重启网络服务文章源自技术奇点-https://www.xerer.com/archives/32683.html

    service network restart 或者 systemctl restart netwrok
    就可以上网了~文章源自技术奇点-https://www.xerer.com/archives/32683.html

    这里讲的方法很简单,就是利用DHCP让服务器自动获取IP地址,是系统指定的IP地址,不能自己挑选,如果想自己分配IP地址的话,那么请接着看CentOS7 配置静态IP地址文章源自技术奇点-https://www.xerer.com/archives/32683.html

    3. CentOS7 配置静态IP地址

    兄弟连的 Linux 教程,在2.4章讲到配置 Linux CentOS 服务器IP地址的时候,就懵逼了,因为教程制作时间比较早,用的是 CentOS 6 演示的,很多已经不适用于最新版本的CentOS了,今天 Forece 给大家讲一下如何在 CentOS 中配置静态IP地址。也就是说可以自己分配服务器指定的IP地址。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    其实很简单,一句话就能解决的问题,首先 ip addr 查看自己的网卡名字,xerer这里是 ens33文章源自技术奇点-https://www.xerer.com/archives/32683.html

    Linux网络配置:CentOS7无法运行 ifconfig如何设置静态IP地址?文章源自技术奇点-https://www.xerer.com/archives/32683.html

    和上一章其实类似,就是多改一些参数。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    同样开始编辑 /etc/sysconfig/network-scripts/ifcfg-ens33 文件 (最后的这个ens33就是你的网卡名字)文章源自技术奇点-https://www.xerer.com/archives/32683.html

     文章源自技术奇点-https://www.xerer.com/archives/32683.html

    vi /etc/sysconfig/network-scripts/ifcfg-ens33文章源自技术奇点-https://www.xerer.com/archives/32683.html

    按键盘 ‘i’ 键进入编辑模式,按照下方参数修改,然后按 ESC 键,再敲 :wq! 保存退出。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    Linux网络配置:CentOS7无法运行 ifconfig如何设置静态IP地址?文章源自技术奇点-https://www.xerer.com/archives/32683.html

    将 BOOTPROTO = dhcp(自动获取IP地址) 更改为 BOOTPROTO = static(静态IP地址)
    将 ONBOOT=no(开机不使用配置) 更改为 ONBOOT=yes(开机使用配置)文章源自技术奇点-https://www.xerer.com/archives/32683.html

    再添加下面的信息
    IPADDR=192.168.0.200(IP地址)
    NETMASK=255.255.255.0(子网掩码)
    GATEWAY=192.168.0.1(网关)
    DNS1=8.8.8.8(首选DNS)文章源自技术奇点-https://www.xerer.com/archives/32683.html

    再多说几句,因为是针对兄弟连虚拟机安装Linux的教程写的,所以可能看xerer文章的都是新手,上边几个参数,比如IP,网关,掩码等等可以在 Windows 中 cmd 命令中敲打 ipconfig 查看。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    最后再附上一章给强迫症患者观看的如何将 ens33网卡改名为 eth0 网卡。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    4. CentOS7 将网卡 ens33 改为 eth0

    兄弟连的 Linux 教程,在2.4章讲到配置 Linux CentOS 服务器IP地址的时候,就懵逼了,因为教程制作时间比较早,用的是 CentOS 6 演示的,很多已经不适用于最新版本的CentOS了,今天xerer 给大家讲一下如何在 CentOS 中将ens33网卡更改为视频中的eth0网卡。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    其实不改也没关系,就是个名字而已,不过有时候强迫症犯起病来连自己都怕。那么步入正题文章源自技术奇点-https://www.xerer.com/archives/32683.html

    vi命令再说一遍!按键盘 ‘i’ 键进入编辑模式,按照下方参数修改,然后按 ESC 键,再敲 :wq! 保存退出。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    1. 用vi命令修改grub文章源自技术奇点-https://www.xerer.com/archives/32683.html

    vi /etc/sysconfig/grub
    增加参数:文章源自技术奇点-https://www.xerer.com/archives/32683.html

    net.ifnames=0 biosdevname=0
    修改为:文章源自技术奇点-https://www.xerer.com/archives/32683.html

    GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
    2. 重新生成grub文件文章源自技术奇点-https://www.xerer.com/archives/32683.html

    grub2-mkconfig
    3. 备份并创建 eth0 的网卡文件,其实就是复制就的网卡文件,改个名文章源自技术奇点-https://www.xerer.com/archives/32683.html

    cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
    mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
    4. 修改 eth0 的网卡文件文章源自技术奇点-https://www.xerer.com/archives/32683.html

    vi /etc/sysconfig/network-scripts/ifcfg-eth0
    NAME=eth0
    DEVICE=eth0文章源自技术奇点-https://www.xerer.com/archives/32683.html

    将上边两个参数修改一下,然后重启网络服务即可文章源自技术奇点-https://www.xerer.com/archives/32683.html

    service network restart 或者 systemctl restart netwrok
    这里 xerer 又碰到错误,重启网络不成功,后来直接 reboot 重启后正常了。文章源自技术奇点-https://www.xerer.com/archives/32683.html

    文章源自技术奇点-https://www.xerer.com/archives/32683.html
    weinxin
    微信公众号
    扫码关注公众号获取资源下载及吃瓜爆料

    发表评论

    匿名网友