General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to change a kernel parameter in linux?

SOLVED
Go to solution
oiram
Regular Advisor

How to change a kernel parameter in linux?

Hi all,

I need to know how to change a kernel parameter in linux and if is possible to make it online. The parameter I want to change is ip_forwarding.

Regards.
5 REPLIES
Craig Kelley
Valued Contributor

Re: How to change a kernel parameter in linux?


Check out Documentation/filesystems/proc.txt in the kernel source tree. There is a section on the ip_forward parameter.
Kodjo Agbenu
Honored Contributor
Solution

Re: How to change a kernel parameter in linux?

Hi,

With Linux, certain kernel parameters can be changed "on-the-fly" using /proc subsystem features.

Here is an example :

echo "1" >/proc/sys/net/ipv4/ip_forward
echo "134217728" >/proc/sys/kernel/shmmax

Of course you can put these lines in /etc/rc.local to have it done at system bootup.

On a RedHat system, this is already done for you. Just edit /etc/sysctl.conf file as follows :

net.ipv4.ip_forward = 0
kernel.shmmax = 134217728

Good luck.

Kodjo
Learn and explain...
oiram
Regular Advisor

Re: How to change a kernel parameter in linux?

Hi all,

First of all thanks for your help, I have found the commnad sysctl that seems the right way to change the value of the kernel parameters:

[root@cache1]# sysctl -w net.ipv4.ip_forward=0
net.ipv4.ip_forward = 0

I have now another problem is that the value of the parameter was 1 although in the file sysctl.conf it was 0:

[root@cache1]# more /etc/sysctl.conf
# Disables packet forwarding
net.ipv4.ip_forward = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
# Disables automatic defragmentation (needed for masquerading, LVS)
net.ipv4.ip_always_defrag = 0
# Disables the magic-sysrq key
kernel.sysrq = 0

Any idea?

Regards.

Re: How to change a kernel parameter in linux?

It looks like you're setting things up correctly. Did you reboot after editing your sysctl.conf file (or run 'sysctl -p')? I do remember having one system, it was Red Hat 7.1 I believe, that refused to obey the 'net.ipv4.ip_forward' line in the sysctl.conf file. I spent quite a while trying to figure it out, and I got nowhere. I ended up manually putting 'sysctl -w net.ipv4.ip_forward=0/1' in my /etc/rc.local file. I was trying to turn ON the forwarding, so it wasn't a big issue for me. However, for you, there will be a couple of seconds/minutes of forwarding between rc.sysinit and rc.local, when your other services are starting. Just something to keep in mind. Let us know if you figure out why it's not working. Best of luck to you. :-)
Kodjo Agbenu
Honored Contributor

Re: How to change a kernel parameter in linux?

Try "grep -rli ip_forward /etc/rc.d/init.d"

You may find the shell script that forces the ip_forward parameter.

Good luck.

Kodjo
Learn and explain...