Linux ifconfig command ip address , subnet mask permanent

30,263

Solution 1

If you don't want the sys V way, you can add

/sbin/route add default gw 192.178.1.1

to /etc/rc.d/rc.local . Although, editing the initi scripts as qweet points out is better.

Solution 2

The ifcfg script contains permanent details of your internet devices. You can find them in /etc/sysconfig/network-scripts/ifcfg-<devicetype><num>. There, you should alter/add the following to ifcfg-eth1:

BOOTPROTO=static
IPADDR=192.168.1.2 
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

Which should do the trick. To see the changes in effect, do a sudo /etc/init.d/network restart

Share:
30,263
edotan
Author by

edotan

Updated on September 18, 2022

Comments

  • edotan
    edotan over 1 year

    I would like to change my ip address and subnet mask with the following command: ifconfig eth1 192.168.1.2 netmask 255.255.255.0 up

    and

    route add default gw 192.168.1.1

    when I reboot my linux it's gone. I would like to keep it permanent with this command. is it possible?

    Thanks