Definite's Extractor

My findings on Life, Linux, Open Source, and so on.

Monthly Archives: August 2014

Fedora and RHEL: Configure static IP and disable NetworkManager

If your machine is always stay in same place and use the same socket. You can consider disable NetworkMange. This article shows step-by-step instruction. I assume either know your network configuration or your machine is able to connect with NetworkManager.

My environment is RHEL 7, other distro or version should use the corresponding commands.

0. Preparation: Get the current working configuration

Before trying anything nasty, backup first.
In terms of network config, you need run following commands:

ip addr
So you know your network interface (e.g. eth0 or enp0s25 ), MAC address and IP
ip route
(Important!) So you know the current working route table
dig | grep SERVER
So you know the current working DNS server

1. Disable NetworkManger service

To disable the network manager

sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager

Should you need to start network server, use

sudo systemctl start network.service

2. Edit ifcfg.<yourInterface>

Suppose your network interface is enp0s25, then edit the file /etc/sysconfig/network-scripts/ifcfg-enp0s25, and replace the "REPLACE....":

HWADDR=REPLACE:WITH:YOUR:MAC:ADDRESS:HERE
TYPE=Ethernet
BOOTPROTO=none
IPADDR0=REPLACE.YOUR.IP.ADDRESS
PREFIX0=23
GATEWAY0=REPLACE.YOUR.GATEWAY.IP
DNS0=REPLACE.YOUR.DNS.IP
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=no
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_PRIVACY=no
NAME=enp0s25
ONBOOT=yes
DOMAIN="REPLACE.YOUR.DOMAIN"
NM_CONTROLLED="no"

3. Edit route.<yourInterface>

Suppose your network interface is enp0s25, then edit the file /etc/sysconfig/network-scripts/route-enp0s25, and replace the "REPLACE....":

ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=REPLACE.YOUR.GATEWAY.IP
METRIC0=0

ADDRESS1=REPLACE.YOUR.NETWORK.IP
NETMASK1=REPLACE.YOUR.NETMASK.IP
GATEWAY1=0.0.0.0
METRIC1=0

4. Restart network interface and test it

Suppose your network interface is enp0s25, you can restart it by

sudo ifdown enp0s25
sudo ifup enp0s25

After the network interface restart, you can now test it with ping, web browse,
and reboot the machine and see whether the setting persist. Enjoy!