Jump to content

Настройка инет-шлюза во freebsd


Recommended Posts

Здравствуйте! Сложилась такая вот ситуация: у меня есть адсл-роутер, его внутренний ИП - 192.168.1.1. Есть 2 сетевых интерфейса: re1 - к нему подключен роутер, re0 - идет на сеть, его ИП - 72.207.1.148, так вот сам вопрос. Как нужно сконфигурировать устройства и вообще систему, чтобы раздавать инет юзерам по сети?

Дальше я выложил файл настроек, но так настроить у меня не получилось. В чем собственно проблема - понять не могу, инета даже на этой машине (сервере) нету, НАТ я возможно и неправильно настроил, но суть пока что не в єтом, на машине, к которой роутер подключен даже инета нету, НАТ думаю смогу настроить.

Вот файл rc.conf

amd_enable="YES"
gateway_enable="YES"
hostname="k.kanivnet"
ifconfig_re0="inet 72.207.1.148  netmask 255.255.0.0"
apachectl_enable="YES"
inetd_enable="YES"
linux_enable="YES"
nfs_client_enable="YES"
rpcbind_enable="YES"
sshd_enable="YES"
usbd_enable="YES"
hostname="k.kanivnet"
ifconfig_re1="inet 192.168.1.1  netmask 255.255.255.0"
ipv6_enable="YES"
defaultrouter="192.168.1.1"
hostname="k.kanivnet"
# NATD
gateway_enable="YES"
firewall_enable="YES"
firewall_type="OPEN"
natd_enable="YES"
natd_interface="re1"

Вродь все описал. Спасибо.

Link to post
Share on other sites

Насчет внешнего ипа - у меня он динамичный:) Как тогда быть?

Вот содержание файерволла:

rc.firewall

#!/bin/sh -
# Suck in the configuration variables.
if [ -z "${source_rc_confs_defined}" ]; then
if [ -r /etc/defaults/rc.conf ]; then
 . /etc/defaults/rc.conf
 source_rc_confs
elif [ -r /etc/rc.conf ]; then
 . /etc/rc.conf
fi
fi

############
# Define the firewall type in /etc/rc.conf.  Valid values are:
#   open     - will allow anyone in
#   client   - will try to protect just this machine
#   simple   - will try to protect a whole network
#   closed   - totally disables IP services except via lo0 interface
#   UNKNOWN  - disables the loading of firewall rules.
#   filename - will load the rules in the given filename (full path required)
#
# For ``client'' and ``simple'' the entries below should be customized
# appropriately.

############
#
# If you don't know enough about packet filtering, we suggest that you
# take time to read this book:
#
#	Building Internet Firewalls, 2nd Edition
#	Brent Chapman and Elizabeth Zwicky
#
#	O'Reilly & Associates, Inc
#	ISBN 1-56592-871-7
#	http://www.ora.com/
#	http://www.oreilly.com/catalog/fire2/
#
# For a more advanced treatment of Internet Security read:
#
#	Firewalls & Internet Security
#	Repelling the wily hacker
#	William R. Cheswick, Steven M. Bellowin
#
#	Addison-Wesley
#	ISBN 0-201-63357-4
#	http://www.awl.com/
#	http://www.awlonline.com/product/0%2C2627%...>setup_loopback () {
############
# Only in rare cases do you want to change these rules
#
${fwcmd} add 100 pass all from any to any via lo0
${fwcmd} add 200 deny all from any to 127.0.0.0/8
${fwcmd} add 300 deny ip from 127.0.0.0/8 to any
}

if [ -n "${1}" ]; then
firewall_type="${1}"
fi

############
# Set quiet mode if requested
#
case ${firewall_quiet} in
[Yy][Ee][ss])
fwcmd="/sbin/ipfw -q"
;;
*)
fwcmd="/sbin/ipfw"
;;
esac

############
# Flush out the list before we begin.
#
${fwcmd} -f flush

############
# Network Address Translation.  All packets are passed to natd(8)
# before they encounter your remaining rules.  The firewall rules
# will then be run again on each packet after translation by natd
# starting at the rule number following the divert rule.
#
# For ``simple'' firewall type the divert rule should be put to a
# different place to not interfere with address-checking rules.
#
case ${firewall_type} in
[Oo][Pp][Ee][Nn]|[Cc][Ll][ii][Ee][Nn][Tt])
case ${natd_enable} in
[Yy][Ee][ss])
 if [ -n "${natd_interface}" ]; then
 	${fwcmd} add 50 divert natd all from any to any via ${natd_interface}
 fi
;;
esac
esac

############
# If you just configured ipfw in the kernel as a tool to solve network
# problems or you just want to disallow some particular kinds of traffic
# then you will want to change the default policy to open.  You can also
# do this as your only action by setting the firewall_type to ``open''.
#
# ${fwcmd} add 65000 pass all from any to any


# Prototype setups.
#
case ${firewall_type} in
[Oo][Pp][Ee][Nn])
setup_loopback
${fwcmd} add 65000 pass all from any to any
;;

[Cc][Ll][ii][Ee][Nn][Tt])
############
# This is a prototype setup that will protect your system somewhat
# against people from outside your own network.
############

# set these to your network and netmask and ip
net="192.0.2.0"
mask="255.255.255.0"
ip="192.0.2.1"

setup_loopback

# Allow any traffic to or from my own net.
${fwcmd} add pass all from ${ip} to ${net}:${mask}
${fwcmd} add pass all from ${net}:${mask} to ${ip}

# Allow TCP through if setup succeeded
${fwcmd} add pass tcp from any to any established

# Allow IP fragments to pass through
${fwcmd} add pass all from any to any frag

# Allow setup of incoming email
${fwcmd} add pass tcp from any to ${ip} 25 setup

# Allow setup of outgoing TCP connections only
${fwcmd} add pass tcp from ${ip} to any setup

# Disallow setup of all other TCP connections
${fwcmd} add deny tcp from any to any setup

# Allow DNS queries out in the world
${fwcmd} add pass udp from ${ip} to any 53 keep-state

# Allow NTP queries out in the world
${fwcmd} add pass udp from ${ip} to any 123 keep-state

# Everything else is denied by default, unless the
# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
# config file.
;;

[ss][ii][Mm][Pp][Ll][Ee])
############
# This is a prototype setup for a simple firewall.  Configure this
# machine as a DNS and NTP server, and point all the machines
# on the inside at this machine for those services.
############

# set these to your outside interface network and netmask and ip
oif="ed0"
onet="192.0.2.0"
omask="255.255.255.240"
oip="192.0.2.1"

# set these to your inside interface network and netmask and ip
iif="ed1"
inet="192.0.2.16"
imask="255.255.255.240"
iip="192.0.2.17"

setup_loopback

# Stop spoofing
${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}

# Stop RFC1918 nets on the outside interface
${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif}
${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif}
${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif}

# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
# on the outside interface
${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif}
${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif}
${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif}
${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif}
${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif}

# Network Address Translation.  This rule is placed here deliberately
# so that it does not interfere with the surrounding address-checking
# rules.  If for example one of your internal LAN machines had its IP
# address set to 192.0.2.1 then an incoming packet for it after being
# translated by natd(8) would match the `deny' rule above.  Similarly
# an outgoing packet originated from it before being translated would
# match the `deny' rule below.
case ${natd_enable} in
[Yy][Ee][ss])
 if [ -n "${natd_interface}" ]; then
 	${fwcmd} add divert natd all from any to any via ${natd_interface}
 fi
;;
esac
${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif}
${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif}
${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif}
# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
# on the outside interface
${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif}
${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif}
${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif}
${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif}
${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif}

# Allow TCP through if setup succeeded
${fwcmd} add pass tcp from any to any established

# Allow IP fragments to pass through
${fwcmd} add pass all from any to any frag

# Allow setup of incoming email
${fwcmd} add pass tcp from any to ${oip} 25 setup

# Allow access to our DNS
${fwcmd} add pass tcp from any to ${oip} 53 setup
${fwcmd} add pass udp from any to ${oip} 53
${fwcmd} add pass udp from ${oip} 53 to any

# Allow access to our WWW
${fwcmd} add pass tcp from any to ${oip} 80 setup

# Reject&Log all setup of incoming connections from the outside
${fwcmd} add deny log tcp from any to any in via ${oif} setup

# Allow setup of any other TCP connection
${fwcmd} add pass tcp from any to any setup

# Allow DNS queries out in the world
${fwcmd} add pass udp from ${oip} to any 53 keep-state

# Allow NTP queries out in the world
${fwcmd} add pass udp from ${oip} to any 123 keep-state

# Everything else is denied by default, unless the
# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
# config file.
;;

[Cc][Ll][Oo][ss][Ee][Dd])
setup_loopback
;;
[uu][Nn][Kk][Nn][Oo][Ww][Nn])
;;
*)
if [ -r "${firewall_type}" ]; then
 ${fwcmd} ${firewall_flags} ${firewall_type}
fi
;;
esac

 

rc.firewall6

#!/bin/sh -
############
# Setup system for IPv6 firewall service.
# $FreeBSD: src/etc/rc.firewall6,v 1.15.2.1 2005/10/10 09:49:25 ume Exp $

# Suck in the configuration variables.
if [ -z "${source_rc_confs_defined}" ]; then
if [ -r /etc/defaults/rc.conf ]; then
 . /etc/defaults/rc.conf
 source_rc_confs
elif [ -r /etc/rc.conf ]; then
 . /etc/rc.conf
fi
fi

############
# Define the firewall type in /etc/rc.conf.  Valid values are:
#   open     - will allow anyone in
#   client   - will try to protect just this machine
#   simple   - will try to protect a whole network
#   closed   - totally disables IP services except via lo0 interface
#   UNKNOWN  - disables the loading of firewall rules.
#   filename - will load the rules in the given filename (full path required)
#
# For ``client'' and ``simple'' the entries below should be customized
# appropriately.

############
#
# If you don't know enough about packet filtering, we suggest that you
# take time to read this book:
#
#	Building Internet Firewalls, 2nd Edition
#	Brent Chapman and Elizabeth Zwicky
#
#	O'Reilly & Associates, Inc
#	ISBN 1-56592-871-7
#	http://www.ora.com/
#	http://www.oreilly.com/catalog/fire2/
#
# For a more advanced treatment of Internet Security read:
#
#	Firewalls & Internet Security
#	Repelling the wily hacker
#	William R. Cheswick, Steven M. Bellowin
#
#	Addison-Wesley
#	ISBN 0-201-63357-4
#	http://www.awl.com/
#	http://www.awlonline.com/product/0%2C2627%...
setup_local () {
############
# Only in rare cases do you want to change these rules
#
${fw6cmd} add 100 pass all from any to any via lo0
${fw6cmd} add 200 deny all from any to ::1
${fw6cmd} add 300 deny all from ::1 to any
#
# ND
#
# DAD
${fw6cmd} add pass ipv6-icmp from :: to ff02::/16
# RS, RA, NS, NA, redirect...
${fw6cmd} add pass ipv6-icmp from fe80::/10 to fe80::/10
${fw6cmd} add pass ipv6-icmp from fe80::/10 to ff02::/16
}

if [ -n "${1}" ]; then
ipv6_firewall_type="${1}"
fi

############
# Set quiet mode if requested
#
case ${ipv6_firewall_quiet} in
[Yy][Ee][ss])
fw6cmd="/sbin/ip6fw -q"
;;
*)
fw6cmd="/sbin/ip6fw"
;;
esac

############
# Flush out the list before we begin.
#
${fw6cmd} -f flush

############
# If you just configured ipfw in the kernel as a tool to solve network
# problems or you just want to disallow some particular kinds of traffic
# then you will want to change the default policy to open.  You can also
# do this as your only action by setting the ipv6_firewall_type to ``open''.
#
# ${fw6cmd} add 65000 pass all from any to any


# Prototype setups.
#
case ${ipv6_firewall_type} in
[Oo][Pp][Ee][Nn])
setup_local
${fw6cmd} add 65000 pass all from any to any
;;

[Cc][Ll][ii][Ee][Nn][Tt])
############
# This is a prototype setup that will protect your system somewhat
# against people from outside your own network.
############

# set these to your network and prefixlen and ip
#
# This needs more work
#
net="2001:db8:2:1::"
prefixlen="64"
ip="2001:db8:2:1::1"

setup_local

# Allow any traffic to or from my own net.
${fw6cmd} add pass all from ${ip} to ${net}/${prefixlen}
${fw6cmd} add pass all from ${net}/${prefixlen} to ${ip}

# Allow any link-local multicast traffic
${fw6cmd} add pass all from fe80::/10 to ff02::/16
${fw6cmd} add pass all from ${net}/${prefixlen} to ff02::/16

# Allow TCP through if setup succeeded
${fw6cmd} add pass tcp from any to any established

# Allow IP fragments to pass through
${fw6cmd} add pass all from any to any frag

# Allow setup of incoming email
${fw6cmd} add pass tcp from any to ${ip} 25 setup

# Allow setup of outgoing TCP connections only
${fw6cmd} add pass tcp from ${ip} to any setup

# Disallow setup of all other TCP connections
${fw6cmd} add deny tcp from any to any setup

# Allow DNS queries out in the world
${fw6cmd} add pass udp from any 53 to ${ip}
${fw6cmd} add pass udp from ${ip} to any 53

# Allow NTP queries out in the world
${fw6cmd} add pass udp from any 123 to ${ip}
${fw6cmd} add pass udp from ${ip} to any 123

# Allow ICMPv6 destination unreach
${fw6cmd} add pass ipv6-icmp from any to any icmptypes 1

# Allow NS/NA/toobig (don't filter it out)
${fw6cmd} add pass ipv6-icmp from any to any icmptypes 2,135,136

# Everything else is denied by default, unless the
# IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
# config file.
;;

[ss][ii][Mm][Pp][Ll][Ee])
############
# This is a prototype setup for a simple firewall.  Configure this
# machine as a DNS and NTP server, and point all the machines
# on the inside at this machine for those services.
############

# set these to your outside interface network and prefixlen and ip
oif="ed0"
onet="2001:db8:2:1::"
oprefixlen="64"
oip="2001:db8:2:1::1"

# set these to your inside interface network and prefixlen and ip
iif="ed1"
inet="2001:db8:2:2::"
iprefixlen="64"
iip="2001:db8:2:2::1"

setup_local

# Stop spoofing
${fw6cmd} add deny all from ${inet}/${iprefixlen} to any in via ${oif}
${fw6cmd} add deny all from ${onet}/${oprefixlen} to any in via ${iif}

# Stop unique local unicast address on the outside interface
${fw6cmd} add deny all from fc00::/7 to any via ${oif}
${fw6cmd} add deny all from any to fc00::/7 via ${oif}

# Stop site-local on the outside interface
${fw6cmd} add deny all from fec0::/10 to any via ${oif}
${fw6cmd} add deny all from any to fec0::/10 via ${oif}

# Disallow "internal" addresses to appear on the wire.
${fw6cmd} add deny all from ::ffff:0.0.0.0/96 to any via ${oif}
${fw6cmd} add deny all from any to ::ffff:0.0.0.0/96 via ${oif}

# Disallow packets to malicious IPv4 compatible prefix.
${fw6cmd} add deny all from ::224.0.0.0/100 to any via ${oif}
${fw6cmd} add deny all from any to ::224.0.0.0/100 via ${oif}
${fw6cmd} add deny all from ::127.0.0.0/104 to any via ${oif}
${fw6cmd} add deny all from any to ::127.0.0.0/104 via ${oif}
${fw6cmd} add deny all from ::0.0.0.0/104 to any via ${oif}
${fw6cmd} add deny all from any to ::0.0.0.0/104 via ${oif}
${fw6cmd} add deny all from ::255.0.0.0/104 to any via ${oif}
${fw6cmd} add deny all from any to ::255.0.0.0/104 via ${oif}

${fw6cmd} add deny all from ::0.0.0.0/96 to any via ${oif}
${fw6cmd} add deny all from any to ::0.0.0.0/96 via ${oif}

# Disallow packets to malicious 6to4 prefix.
${fw6cmd} add deny all from 2002:e000::/20 to any via ${oif}
${fw6cmd} add deny all from any to 2002:e000::/20 via ${oif}
${fw6cmd} add deny all from 2002:7f00::/24 to any via ${oif}
${fw6cmd} add deny all from any to 2002:7f00::/24 via ${oif}
${fw6cmd} add deny all from 2002:0000::/24 to any via ${oif}
${fw6cmd} add deny all from any to 2002:0000::/24 via ${oif}
${fw6cmd} add deny all from 2002:ff00::/24 to any via ${oif}
${fw6cmd} add deny all from any to 2002:ff00::/24 via ${oif}

${fw6cmd} add deny all from 2002:0a00::/24 to any via ${oif}
${fw6cmd} add deny all from any to 2002:0a00::/24 via ${oif}
${fw6cmd} add deny all from 2002:ac10::/28 to any via ${oif}
${fw6cmd} add deny all from any to 2002:ac10::/28 via ${oif}
${fw6cmd} add deny all from 2002:c0a8::/32 to any via ${oif}
${fw6cmd} add deny all from any to 2002:c0a8::/32 via ${oif}

${fw6cmd} add deny all from ff05::/16 to any via ${oif}
${fw6cmd} add deny all from any to ff05::/16 via ${oif}

# Allow TCP through if setup succeeded
${fw6cmd} add pass tcp from any to any established

# Allow IP fragments to pass through
${fw6cmd} add pass all from any to any frag

# Allow setup of incoming email
${fw6cmd} add pass tcp from any to ${oip} 25 setup

# Allow access to our DNS
${fw6cmd} add pass tcp from any to ${oip} 53 setup
${fw6cmd} add pass udp from any to ${oip} 53
${fw6cmd} add pass udp from ${oip} 53 to any

# Allow access to our WWW
${fw6cmd} add pass tcp from any to ${oip} 80 setup

# Reject&Log all setup of incoming connections from the outside
${fw6cmd} add deny log tcp from any to any in via ${oif} setup

# Allow setup of any other TCP connection
${fw6cmd} add pass tcp from any to any setup

# Allow DNS queries out in the world
${fw6cmd} add pass udp from any 53 to ${oip}
${fw6cmd} add pass udp from ${oip} to any 53

# Allow NTP queries out in the world
${fw6cmd} add pass udp from any 123 to ${oip}
${fw6cmd} add pass udp from ${oip} to any 123

# Allow RIPng
#${fw6cmd} add pass udp from fe80::/10 521 to ff02::9 521
#${fw6cmd} add pass udp from fe80::/10 521 to fe80::/10 521

# Allow ICMPv6 destination unreach
${fw6cmd} add pass ipv6-icmp from any to any icmptypes 1

# Allow NS/NA/toobig (don't filter it out)
${fw6cmd} add pass ipv6-icmp from any to any icmptypes 2,135,136

# Everything else is denied by default, unless the
# IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
# config file.
;;

[Cc][Ll][Oo][ss][Ee][Dd])
# Only enable the loopback interface
${fw6cmd} add 100 pass all from any to any via lo0
;;
[uu][Nn][Kk][Nn][Oo][Ww][Nn])
;;
*)
if [ -r "${ipv6_firewall_type}" ]; then
 ${fw6cmd} ${ipv6_firewall_flags} ${ipv6_firewall_type}
fi
;;
esac

Ну вот в принципе и все. Честно сказать, я мало понимаю в этом... Во всем, что относится к юниксам и сетям я чайник.

Link to post
Share on other sites

не понимаешь - не делаешь.

Разбирать твои логи из-за твоей лени, тратя собственное время - не мой подход.

 

настраивай на тм, что понимаешь, есть желание научится - handbook freebsd

Link to post
Share on other sites

За основу можешь взять вот это: http://bardak.blood.ru/work/freebsd/router.htm

 

Дальше по манам http://www.freebsd.org/cgi/man.cgi

Плотнее знакомься по ходу с http://www.freebsd.org/doc/ru_RU.KOI8-R/books/handbook/ ...

 

Формулируй вопросы по примеру: "Как обрезать входящую скорость по IP в ipfw?" (Предварительно воспользовавшись поиском по форуму, вдруг такой вопрос уже кто-то задавал ранее?)

 

Итак, пища к размышлению предоставлена, дерзай...

Link to post
Share on other sites
Почитал  rc.conf поплакал  )))

 

особенно с этого:

 

ifconfig_re1="inet 192.168.1.1  netmask 255.255.255.0"

Вообще-то я попросил помочь, раз все такие умные, то в чем причина? Или сами как только родились, так сразу и все настроили?

За основу можешь взять вот это: http://bardak.blood.ru/work/freebsd/router.htm

 

Дальше по манам http://www.freebsd.org/cgi/man.cgi

Плотнее знакомься по ходу с http://www.freebsd.org/doc/ru_RU.KOI8-R/books/handbook/ ...

 

Формулируй вопросы по примеру: "Как обрезать входящую скорость по IP в ipfw?" (Предварительно воспользовавшись поиском по форуму, вдруг такой вопрос уже кто-то задавал ранее?)

 

Итак, пища к размышлению предоставлена, дерзай...

А Вам спасибки:).

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...