How do I configure the network interfaces persistently in CentOS so it will survive a reboot?

doo*_*oon 6 linux networking centos

I configured a network interface with the following commands:

ifconfig eth0 up
ip addr add 192.168.9.1/28 dev eth0
route add default gw 192.168.0.1
Run Code Online (Sandbox Code Playgroud)

This works. However, when I reboot the machine I lose all the configurations made. How can I make sure this is persistent? I'm using CentOS 6.3.

ger*_*ijk 11

首先,您给定的默认网关配置无效。192.168.0.1不在 的网络内192.168.9.1/28。我怀疑你打错了,所以我假设你的意思192.168.9.10是这里的默认网关。

参照RHEL 6部署指南部8.2的地址和第8.4节的路由:

  1. 创建/编辑/etc/sysconfig/network-scripts/ifcfg-eth0包含以下内容的文件:

    DEVICE=eth0
    BOOTPROTO=none
    ONBOOT=yes
    NETMASK=255.255.255.240 # this is /28
    IPADDR=192.168.9.1
    USERCTL=no
    
    Run Code Online (Sandbox Code Playgroud)
  2. 创建/编辑路由配置文件/etc/sysconfig/network-scripts/route-eth0

    default 192.168.9.10 dev eth0
    
    Run Code Online (Sandbox Code Playgroud)