User:Az990tony/scripts: Difference between revisions

From OLPC
Jump to navigation Jump to search
Line 2: Line 2:


=== fire-start ===
=== fire-start ===
#!/bin/sh
#!/bin/sh
#
#
# Copyright (c) 2008 Tony Pearson.
# Copyright (c) 2008 Tony Pearson.
#
#
# Licensed under the MIT license for contribution to the
# Licensed under the MIT license for contribution to the
# One Laptop per Child (OLPC) foundation.
# One Laptop per Child (OLPC) foundation.
#
#
# Permission is hereby granted, free of charge, to any person
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# Software is furnished to do so, subject to the following
# conditions:
# conditions:
#
#
# The above copyright notice and this permission notice shall be
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# included in all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# OTHER DEALINGS IN THE SOFTWARE.

#
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# For more information see the Open Source Initiative:

# http://www.opensource.org/licenses/mit-license.php
# OTHER DEALINGS IN THE SOFTWARE.
#

# The following was based on examples from "Linux Networking Cookbook"
#
# by Carla Schroder, O'Reilly Media, Inc.

#
# For more information see the Open Source Initiative:
# fire-start (written in Bash) place in /root/bin to execute

# http://www.opensource.org/licenses/mit-license.php
mod="/sbin/modprobe"

$mod ip_tables
#
$mod ip_conntrack

$mod iptable_filter
# The following was based on examples from "Linux Networking Cookbook"
$mod iptable_nat

$mod iptable_mangle
# by Carla Schroder, O'Reilly Media, Inc.
$mod ipt_LOG

$mod ipt_limit

$mod ipt_state

$mod ipt_MASQUERADE
mod="/sbin/modprobe"
$mod ip_nat_ftp

$mod ip_tables
$mod ip_conntrack_ftp

# display that modules are loaded
$mod ip_conntrack
lsmod | grep ^ip

$mod iptable_filter
# define variables

ipt="/sbin/iptables"
$mod iptable_nat

# WAN Wide Area Network, the address to the Internet outside-world
$mod iptable_mangle
WAN_IFACE="eth0"

WAN_IP="192.168.0.29"
$mod ipt_LOG

# LAN Local Area Network, for the School Server (XS)
$mod ipt_limit
LAN_IFACE="eth1"

$mod ipt_state
#Flush out previous tables
$mod ipt_MASQUERADE
$ipt -F
$mod ip_nat_ftp
$ipt -t nat -F
$mod ip_conntrack_ftp
$ipt -t mangle -F

$ipt -X
# display that modules are loaded
$ipt -t nat -X
lsmod | grep ^ip
$ipt -t mangle -X

# define variables
#set default policies
ipt="/sbin/iptables"
$ipt -P INPUT ACCEPT # Normally DROP

$ipt -P FORWARD ACCEPT # Normally DROP
# WAN Wide Area Network, the address to the Internet outside-world
$ipt -P OUTPUT ACCEPT
WAN_IFACE="eth0"
$ipt -t nat -P OUTPUT ACCEPT
WAN_IP="192.168.0.29"
$ipt -t nat -P PREROUTING ACCEPT

$ipt -t nat -P POSTROUTING ACCEPT
# LAN Local Area Network, for the School Server (XS)
$ipt -t mangle -P PREROUTING ACCEPT
LAN_IFACE="eth1"
$ipt -t mangle -P POSTROUTING ACCEPT

#Flush out previous tables
# enable loopback
$ipt -F
$ipt -t nat -F
$ipt -A INPUT -i lo -j ACCEPT
$ipt -t mangle -F
# enable IP masquerading using Source NAT translation
$ipt -X
#
$ipt -t nat -X
# Any packet sent out to internet will look like it came from this machine
$ipt -t mangle -X
# instead of from the other machines inside the LAN

#
#set default policies
$ipt -t nat -A POSTROUTING -o $WAN_IFACE -j SNAT --to-source $WAN_IP
$ipt -P INPUT ACCEPT # Normally DROP
$ipt -P FORWARD ACCEPT # Normally DROP
# enable outgoing traffic, restrict incoming traffic
$ipt -P OUTPUT ACCEPT
#
$ipt -t nat -P OUTPUT ACCEPT
$ipt -t nat -P PREROUTING ACCEPT
$ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$ipt -A FORWARD -i $WAN_IFACE -o $LAN_IFACE \
$ipt -t nat -P POSTROUTING ACCEPT
$ipt -t mangle -P PREROUTING ACCEPT
-m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A FORWARD -i $LAN_IFACE -o $WAN_IFACE \
$ipt -t mangle -P POSTROUTING ACCEPT
-m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# enable loopback
# enable ICMP messages
$ipt -A INPUT -i lo -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

$ipt -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
# enable IP masquerading using Source NAT translation
$ipt -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
#
# Any packet sent out to internet will look like it came from this machine
# instead of from the other machines inside the LAN
#
$ipt -t nat -A POSTROUTING -o $WAN_IFACE -j SNAT --to-source $WAN_IP

# enable outgoing traffic, restrict incoming traffic
#
$ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$ipt -A FORWARD -i $WAN_IFACE -o $LAN_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A FORWARD -i $LAN_IFACE -o $WAN_IFACE -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# enable ICMP messages
$ipt -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT

Revision as of 17:22, 24 February 2008

The following scripts were written by Tony Pearson and licensed under MIT license. In many cases, they borrow heavily from snippets and samples found in books, forums, and the internet.

fire-start

#!/bin/sh
#
# Copyright (c) 2008 Tony Pearson.
#
# Licensed under the MIT license for contribution to the 
# One Laptop per Child (OLPC) foundation.
# 
# Permission is hereby granted, free of charge, to any person 
# obtaining a copy of this software and associated documentation 
# files (the "Software"), to deal in the Software without 
# restriction, including without limitation the rights to use, 
# copy, modify, merge, publish, distribute, sublicense, and/or sell 
# copies of the Software, and to permit persons to whom the 
# Software is furnished to do so, subject to the following 
# conditions: 
# 
# The above copyright notice and this permission notice shall be 
# included in all copies or substantial portions of the Software. 
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
# OTHER DEALINGS IN THE SOFTWARE. 
# 
# For more information see the Open Source Initiative:
# http://www.opensource.org/licenses/mit-license.php
#
# The following was based on examples from  "Linux Networking Cookbook"
# by Carla Schroder, O'Reilly Media, Inc. 
#
# fire-start (written in Bash) place in /root/bin to execute

mod="/sbin/modprobe"
$mod ip_tables
$mod ip_conntrack
$mod iptable_filter
$mod iptable_nat
$mod iptable_mangle
$mod ipt_LOG
$mod ipt_limit
$mod ipt_state
$mod ipt_MASQUERADE
$mod ip_nat_ftp
$mod ip_conntrack_ftp

# display that modules are loaded
lsmod | grep ^ip

# define variables
ipt="/sbin/iptables"

# WAN Wide Area Network, the address to the Internet outside-world
WAN_IFACE="eth0"
WAN_IP="192.168.0.29"

# LAN Local Area Network, for the School Server (XS)
LAN_IFACE="eth1"

#Flush out previous tables
$ipt -F
$ipt -t nat -F
$ipt -t mangle -F
$ipt -X
$ipt -t nat -X
$ipt -t mangle -X

#set default policies
$ipt -P INPUT ACCEPT      # Normally DROP
$ipt -P FORWARD ACCEPT    # Normally DROP
$ipt -P OUTPUT ACCEPT
$ipt -t nat -P OUTPUT ACCEPT
$ipt -t nat -P PREROUTING ACCEPT
$ipt -t nat -P POSTROUTING ACCEPT
$ipt -t mangle -P PREROUTING ACCEPT
$ipt -t mangle -P POSTROUTING ACCEPT

# enable loopback
$ipt -A INPUT -i lo -j ACCEPT

# enable IP masquerading using Source NAT translation
#
# Any packet sent out to internet will look like it came from this machine
# instead of from the other machines inside the LAN
#
$ipt -t nat -A POSTROUTING -o $WAN_IFACE -j SNAT --to-source $WAN_IP

# enable outgoing traffic, restrict incoming traffic
# 
$ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$ipt -A FORWARD -i $WAN_IFACE -o $LAN_IFACE  \
     -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A FORWARD -i $LAN_IFACE -o $WAN_IFACE  \
     -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# enable ICMP messages
$ipt -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT