[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 110: Undefined array key "cached"
[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 111: Undefined array key "normal"
[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 112: Undefined array key "total"
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3391: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3393: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3394: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3395: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
Cabrillo College Linux Classes • View topic - Another way to enable IP forwarding.

Another way to enable IP forwarding.

UNIX/Linux Network Administration

Another way to enable IP forwarding.

Postby Jonathan Simms on Wed Mar 18, 2009 2:51 pm

We know of two ways to enable IP forwarding, the echo 1 > /proc/sys/net/ipv4/ip_forward and to edit the /etc/sysctl.conf file. There is another way- you can add FOWARD_IPV4=yes to the /etc/sysconfig/network file.

[url]http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap9sec93.html[/url]
Jonathan Simms
 
Posts: 119
Joined: Tue Sep 02, 2008 7:11 pm

Re: Another way to enable IP forwarding.

Postby Kayla Smith on Wed Mar 18, 2009 2:55 pm

Cool.

I also learned recently that if you want the "1" value to get from the /etc/sysctl.conf file to take effect right away, you don't have to "service network restart", there's actually a command called "sysctl -p".
Kayla Smith
 
Posts: 67
Joined: Tue Sep 02, 2008 7:11 pm

Re: Another way to enable IP forwarding.

Postby Jonathan Simms on Wed Mar 18, 2009 11:24 pm

I was bored today so I wrote a two scripts that will turn IP Forward on, one is in bash and the other in Python.


[code]#!/bin/bash

one=$(grep ip_forward /etc/sysctl.conf | awk '{ print $3 }')

if [ $UID != 0 ]
then
echo "Must be super user" 1>&2
exit 1
fi

if [ $one == 1 ]
then
echo "IP Forwarding is already on" 1>&2
elif [ $one == 0 ]
then
sed -i 's/ip_forward = 0/ip_forward = 1/' /etc/sysctl.conf
sysctl -p > /dev/null
echo "IP Forwarding is now on"
fi
[/code]
[code]#!/usr/bin/python

import fileinput
from os import popen, getuid
from sys import exit

zero = 'net.ipv4.ip_forward = 0'
one = 'net.ipv4.ip_forward = 1'
file = open('/etc/sysctl.conf')

if getuid() != 0:
print "Must be super user"
exit(1)

for lines in file:
if zero in lines:
for line in fileinput.FileInput('/etc/sysctl.conf', inplace=1):
line = line.replace(zero, one)
print line.strip()
print "IP Forwarding is now on"
popen('sysctl -p')
elif one in lines:
print "IP Forwading is already on"

file.close()
[/code]
Last edited by Jonathan Simms on Thu Mar 19, 2009 1:27 pm, edited 1 time in total.
Jonathan Simms
 
Posts: 119
Joined: Tue Sep 02, 2008 7:11 pm

Re: Another way to enable IP forwarding.

Postby Rich Simms on Thu Mar 19, 2009 7:22 am

Nice! - Rich
User avatar
Rich Simms
Site Admin
 
Posts: 640
Joined: Thu May 15, 2008 2:44 pm


Return to CIS 192 - Spring 2009

Who is online

Users browsing this forum: No registered users and 0 guests

cron