rsync服务器架设(数据同步|文件增量备份)

 

我们在使用服务器发布我们的网站的时候,通常要考虑到文件的备份,而文件的备份比较高效的备份是增加备份,rsync软件就是这样的一个工具。为了实现多个服务器负载均衡,我们需要这几个服务器之间进行数据同步,而rsync软件也能胜任,下面我们来介绍如何架设rsync服务器来达到文件增量备份和数据同步的功能。

什么是rsync

rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用。本文主要讲述的是如何自架rsync服务器,以实现文件传输、备份和镜像。相对tar和wget来说,rsync 也有其自身的优点,比如速度快、安全、高效。

rsync的安装

CentOS服务器,我们可以执行以下命令安装

  1. yum install rsync

对于debian、ubuntu服务器,则是以下命令

  1. sudo apt-get  install  rsync

rsync服务器的配置文件rsyncd.conf

下面我们将涉及到三个文件 rsyncd.conf,rsyncd.secrets 和rsyncd.motd。
rsyncd.conf 是rsync服务器主要配置文件。
rsyncd.secrets是登录rsync服务器的密码文件。
rsyncd.motd是定义rysnc 服务器信息的,也就是用户登录信息。
下面我们分别建立这三个文件。

  1. mkdir /etc/rsyncd

注:在/etc目录下创建一个rsyncd的目录,我们用来存放rsyncd.conf 和rsyncd.secrets文件;

  1. touch /etc/rsyncd/rsyncd.conf

注:创建rsyncd.conf ,这是rsync服务器的配置文件;

  1. touch /etc/rsyncd/rsyncd.secrets

注:创建rsyncd.secrets ,这是用户密码文件;

  1. chmod 600 /etc/rsyncd/rsyncd.secrets

注:为了密码的安全性,我们把权限设为600;

  1. touch /etc/rsyncd/rsyncd.motd

注:创建rsyncd.motd文件,这是定义服务器信息的文件。
下一就是我们修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd 文件的时候了。
rsyncd.conf文件内容:

  1. # Minimal configuration file for rsync daemon
  2. # See rsync(1) and rsyncd.conf(5) man pages for help
  3.  
  4. # This line is required by the /etc/init.d/rsyncd script
  5. pid file = /var/run/rsyncd.pid   
  6. port = 873
  7. address = 192.168.1.171 
  8. #uid = nobody
  9. #gid = nobody   
  10. uid = root   
  11. gid = root   
  12.  
  13. use chroot = yes 
  14. read only = no 
  15.  
  16.  
  17. #limit access to private LANs
  18. hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 
  19. hosts deny=*
  20.  
  21. max connections = 5
  22. motd file = /etc/rsyncd/rsyncd.motd
  23.  
  24. #This will give you a separate log file
  25. #log file = /var/log/rsync.log
  26.  
  27. #This will log every file transferred - up to 85,000+ per user, per sync
  28. #transfer logging = yes
  29.  
  30. log format = %t %a %m %f %b
  31. syslog facility = local3
  32. timeout = 300
  33.  
  34. [linuxsirhome]   
  35. path = /home   
  36. list=yes
  37. ignore errors
  38. auth users = linuxsir
  39. secrets file = /etc/rsyncd/rsyncd.secrets 
  40. comment = linuxsir home 
  41. exclude =   beinan/  samba/     
  42.  
  43. [beinan]
  44. path = /opt
  45. list=no
  46. ignore errors
  47. comment = optdir   
  48. auth users = beinan
  49. secrets file = /etc/rsyncd/rsyncd.secrets

密码文件:/etc/rsyncd/rsyncd.secrets的内容格式;

  1. 用户名:密码
  2. linuxsir:222222
  3. beinan:333333

注: linuxsir是系统用户,这里的密码值得注意,为了安全,你不能把系统用户的密码写在这里。比如你的系统用户 linuxsir 密码是 abcdefg ,为了安全,你可以让rsync 中的linuxsir 为 222222 。这和samba的用户认证的密码原理是差不多的;
rsyncd.motd 文件;
它是定义rysnc 服务器信息的,也就是用户登录信息。比如让用户知道这个服务器是谁提供的等;类似ftp服务器登录时,我们所看到的 linuxsir.org ftp ……。 当然这在全局定义变量时,并不是必须的,你可以用#号注掉,或删除;我在这里写了一个 rsyncd.motd的内容为:

  1. +++++++++++++++++++++++++++
  2. + linuxsir.org  rsync  2002-2007 +
  3. +++++++++++++++++++++++++++

rsyncd.conf文件代码说明

  1. pid file = /var/run/rsyncd.pid

注:告诉进程写到 /var/run/rsyncd.pid 文件中;

  1. port = 873

注:指定运行端口,默认是873,您可以自己指定;

  1. address = 192.168.1.171

注:指定服务器IP地址;

  1. uid = nobody
  2. gid = nobdoy

注:服务器端传输文件时,要发哪个用户和用户组来执行,默认是nobody。 如果用nobody 用户和用户组,可能遇到权限问题,有些文件从服务器上拉不下来。所以我就偷懒,为了方便,用了root 。不过您可以在定义要同步的目录时定义的模块中指定用户来解决权限的问题。

  1. use chroot = yes

用chroot,在传输文件之前,服务器守护程序在将chroot 到文件系统中的目录中,这样做的好处是可能保护系统被安装漏洞侵袭的可能。缺点是需要超级用户权限。另外对符号链接文件,将会排除在外。也就是说,你在rsync服务器上,如果有符号链接,你在备份服务器上运行客户端的同步数据时,只会把符号链接名同步下来,并不会同步符号链接的内容;这个需要自己来尝试;

  1. read only = yes

注:read only 是只读选择,也就是说,不让客户端上传文件到服务器上。还有一个 write only选项,自己尝试是做什么用的吧;

  1. #limit access to private LANs
  2. hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0

注:在您可以指定单个IP,也可以指定整个网段,能提高安全性。格式是ip 与ip 之间、ip和网段之间、网段和网段之间要用空格隔开;

  1. max connections = 5

注:客户端最多连接数;

  1. motd file = /etc/rsyncd/rsyncd.motd

注:motd file 是定义服务器信息的,要自己写 rsyncd.motd 文件内容。当用户登录时会看到这个信息。

  1. log file = /var/log/rsync.log

注:rsync 服务器的日志;

  1. transfer logging = yes

注:这是传输文件的日志;

  1. [linuxsirhome]

注:模块,它为我们提供了一个链接的名字,链接到哪呢,在本模块中,链接到了/home目录;要用[name] 形式;

  1. path = /home

注:指定文件目录所在位置,这是必须指定的;

  1. auth users = linuxsir

注:认证用户是linuxsir ,是必须在 服务器上存在的用户;

  1. list=yes

注:list 意思是把rsync 服务器上提供同步数据的目录在服务器上模块是否显示列出来。默认是yes 。如果你不想列出来,就no ;如果是no是比较安全的,至少别人不知道你的服务器上提供了哪些目录。你自己知道就行了;

  1. ignore errors

注:忽略IO错误,详细的请查文档;

  1. secrets file = /etc/rsyncd/rsyncd.secrets

注:密码存在哪个文件;

  1. comment = linuxsir home  data

注:注释可以自己定义,写什么都行,写点相关的内容就行;

  1. exclude =   beinan/   samba/

注:exclude 是排除的意思,也就是说,要把/home目录下的beinan和samba 排除在外; beinan/和samba/目录之间有空格分开 ;

启动rsync 服务器及防火墙的设置

启动rsync服务器
启动rsync 服务器相当简单,–daemon 是让rsync 以服务器模式运行;

  1. /usr/bin/rsync --daemon  --config=/etc/rsyncd/rsyncd.conf

rsync服务器和防火墙
Linux 防火墙是用iptables,所以我们至少在服务器端要让你所定义的rsync 服务器端口通过,客户端上也应该让通过。

  1. iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT

查看一下防火墙是不是打开了 873端口;

  1. iptables -L

通过rsync客户端来同步数据

  1. rsync -avzP This email address is being protected from spambots. You need JavaScript enabled to view it.::linuxsirhome   linuxsirhome

Password: 这里要输入linuxsir的密码,是服务器端提供的,在前面的例子中,我们用的是 222222,输入的密码并不显示出来;输好后就回车;
注: 这个命令的意思就是说,用linuxsir 用户登录到服务器上,把linuxsirhome数据,同步到本地目录linuxsirhome上。当然本地的目录是可以你自己定义的,比如 linuxsir也是可以的;当你在客户端上,当前操作的目录下没有linuxsirhome这个目录时,系统会自动为你创建一个;当存在linuxsirhome这个目录中,你要注意它的写权限。
说明:
-a 参数,相当于-rlptgoD,-r 是递归 -l 是链接文件,意思是拷贝链接文件;-p 表示保持文件原有权限;-t 保持文件原有时间;-g 保持文件原有用户组;-o 保持文件原有属主;-D 相当于块设备文件;
-z 传输时压缩;
-P 传输进度;
-v 传输时的进度等信息,和-P有点关系,自己试试。可以看文档;

  1. rsync -avzP  --delete This email address is being protected from spambots. You need JavaScript enabled to view it.::linuxsirhome   linuxsirhome

这回我们引入一个 –delete 选项,表示客户端上的数据要与服务器端完全一致,如果 linuxsirhome目录中有服务器上不存在的文件,则删除。最终目的是让linuxsirhome目录上的数据完全与服务器上保持一致;用的时候要小心点,最好不要把已经有重要数所据的目录,当做本地更新目录,否则会把你的数据全部删除;

  1. rsync -avzP  --delete  --password-file=rsync.password  This email address is being protected from spambots. You need JavaScript enabled to view it.::linuxsirhome   linuxsirhome

这次我们加了一个选项 –password-file=rsync.password ,这是当我们以linuxsir用户登录rsync服务器同步数据时,密码将读取 rsync.password 这个文件。这个文件内容只是linuxsir用户的密码。我们要如下做;

  1. touch rsync.password
  2. chmod 600 rsync.password
  3. echo "222222"> rsync.password
  4. rsync -avzP  --delete  --password-file=rsync.password  This email address is being protected from spambots. You need JavaScript enabled to view it.::linuxsirhome   linuxsirhome

注: 这样就不需要密码了;其实这是比较重要的,因为服务器通过crond 计划任务还是有必要的;

让rsync 客户端自动与服务器同步数据

编辑crontab
crontab -e
加入如下代码:

  1. 10 0 * * * rsync -avzP  --delete  --password-file=rsync.password  This email address is being protected from spambots. You need JavaScript enabled to view it.::linuxsirhome   linuxsirhome

表示每天0点10分执行后面的命令。更多crontab用法请参考
http://www.centos.bz/2011/03/auto-run-task-crontab/

Read more...

proftpd 500 OOPS: cannot change directory:/home/ftp

 

但客户端访问提示如下错误:

500 OOPS: cannot change directory:/home/ftp

原因是他的CentOS系统安装了SELinux,因为默认下是没有开启FTP的支持,所以访问时都被阻止了。

//查看SELinux设置

 

# getsebool -a|grep ftp

ftp_home_dir-->off

 

//使用setsebool命令开启

 

 

# setsebool ftp_home_dir 1

 

由于操作系统一旦重启后,这种设置需要重新设置,这里使用-P参数实现.

 

//setsebool使用-P参数,无需每次开机都输入这个命令

 

# setsebool -P ftp_home_dir 1

Read more...

ESXI & PfSense comme firewall

http://forum.online.net/index.php?/topic/1240-tuto-esxi-pfsense-comme-firewall/

 

Bonjour à tous,

Petit Long tuto fastidieux pour ceux qui souhaiterai comme moi, mettre en place PfSense sur leur serveur dédié Dedibox.
A priori rien de bien compliqué sauf qu'en fait si, d'où ce tuto !

Ce que vous devez avoir avant de commencer :
- Un serveur dédié chez Online.net
- Vous avez acheté une IP supplémentaire via le portail Online.net (IP Failover) et l'avez associée à votre serveur.
- Avoir obtenu une adresse MAC virtuelle pour VMware (toujours via le portail Online.net)
- Vous avez déployé ESXI sur votre serveur (toujours via le portail Online.net)

L'objectif est d'avoir une architecture de la sorte :



INTERNET ------ ESXI ----- PfSense (VM1) -|--- SERVEUR LAN 1 (VM2)
                                          |--- SERVEUR LAN 2 (VMx)

L'IP publique (la 1ère) sert uniquement à administrer l'ESXI.
L'IP publique (failover) sera utilisée pour la patte WAN de votre firewall (PfSense).

Configuration d'ESXI (désolé c'est en FR :/)
Dans "Configuration/Mise en réseau"
Cliquer sur "Ajouter gestion réseau...", sélectionnez "Machine virtuelle" puis "Créer un commutateur virtuel", appelez-le comme vous voulez ("VM Network LAN" dans mon exemple) et surtout, renseignez un VLAN ID autre que 0 (1 par exemple).

Sur ce commutateur virtuel seront reliés tous vos serveurs ainsi que la patte LAN du firewall.

Création des VM
C'est ici que ça se complique, vous le verrez ensuite, PfSense doit donc être installé mais surtout un package doit être rajouté une fois l'installation terminée. Pour obtenir ce package il faut bien évidemment une connexion internet chose qui ne fonctionne pas tant que ce package n'est pas installé (:D).

J'ai procédé de la sorte (un peu bourrin mais ça marche) :
Création d'une VM PfSense (disque en thin provisionning, important pour la suite) sur un autre ESXI (un ESXI sur lequel la passerelle est dans le même subnet que l'ip publique car c'est ça qui nous pose problème chez Online.net)

Je ne vous fait pas le détail de l'installation de PfSense ... pensez juste à mettre 2 cartes réseau (LAN + WAN).
Personnellement j'ai fait ça sur mon poste de travail avec VMware Workstation.
L'installation de PfSense terminée configurer les 2 interfaces LAN et WAN et accéder à l'interface web de configuration.

Sur cette interface allez dans "Système/Packages" et installez le package "Shellcmd".
Une fois installé vous pouvez éteindre votre VM et installer VMware Converter sur votre poste de travail.

Vous avez compris la suite, sauvegarder via VMware converter la VM que vous venez de créer sur VMware Workstation et déplacer là sur l'ESXI de Online.net (d'ou le Thin provisionning, vous avez ~300Mo à envoyer).

Une fois votre VM récupérée de l'autre coté, avant de la démarrer, retournez dans la conf des cartes réseaux de la VM :
Carte 1 : 
Adresse MAC Manuelle : saisissez l'adresse MAC fourni sur le portail Online.net (00:50:56: ...)
Etiquette réseau : "VM Network" (le vSwitch principal, PAS celui que vous avez créé tout à l'heure)

Carte 2 :
Adresse MAC Automatique
Etiquette réseau : "VM Network LAN" (ou autre selon le nom que vous avez donné à votre vSwitch secondaire)

Démarrez votre VM PfSense
Reconfigurer vos interfaces LAN et WAN depuis la ligne de commande via la console ESXI et accéder ensuite à l'interface web de management de PfSense depuis un de vos serveur LAN présent sur l'ESXI (oui je sais c'est un peu contraignant mais de toute façon si vous faite tout ça c'est bien pour mettre d'autres VM derrière non ? :D).

Une fois sur l'interface web de management :
- Vérifiez que le module "Shellcmd" est bien présent (il n'y a pas de raison m'enfin bon ...)
- Aller dans "Interfaces/WAN" et spécifiez votre adresse MAC virtuelle dans le champs "MAC address"
- Le champ IP address doit contenir votre ip publique failover (/32)
- Le champ Gateway est pour l'instant vide.

Deux choses à faire :
- Configurer "Shellcmd"
- Spécifier la gateway

Shellcmd
Aller dans "Services/Shellcmd" et ajoutez les 2 commandes suivantes :
route add -inet 88.190.30.1/32 -link -iface em0 
route add default 88.190.30.1 

"88.190.30.1" doit être remplacé par VOTRE passerelle (à priori votre ip publique principale avec un 1 à la fin)

Gateway
Allez dans "System/routing", dans l'onglet "Gateways", ajoutez votre passerelle. 
Problème ici, PfSense n'accepte pas que l'on renseigne une passerelle qui n'appartient pas au même sous réseau que l'ip publique. Soit, saisissez donc votre IP publique failover ! (ce n'est que temporaire pas de panique).
Cochez bien l'option "Default Gateway" à la création.

Allez dans "Diagnostics/Backup-Restore" et sauvegardez votre configuration. Editez là en remplaçant votre ip failover par votre passerelle (attention l'ip failover apparait 2 fois dans la conf, modifiez au bon endroit).
Sauvegardez votre conf et rechargez là via "Diagnostics/Backup-Restore". Votre firewall redémarre.

Après redémarrage, retournez dans "Interfaces/WAN" et sélectionnez votre passerelle dans la liste, cliquez sur "Save" puis "Apply" en haut de la page. Là PfSense ne répond plus sur l'interface web, aller sur la console ESXI et faite un redémarrage du serveur.

Et voilà (ouf), ça devrait être bon.
(Pensez à renseigner les DNS dans "System/General Setup" !)

Vos VM auront donc une adresse LAN uniquement (attention à bien rattacher la carte réseau de vos serveur sur le vSwitch créé manuellement), la passerelle à renseigner étant l'adresse LAN du serveur PfSense.

J'espère n'avoir rien oublié !

Un grand merci à Scruffy, qui m'a mis sur la bonne voie pour la mise en place de PfSense.

Il y a sûrement des méthodes plus simple, n'hésitez pas à les proposer ! (en tout cas la mienne fonctionne

Read more...

PF - pfctl命令备忘

 

# pfctl -d Disable the packet filter.
# pfctl -e Enable the packet filter.

# pfctl -f /etc/pf.conf 载入 pf.conf 文件
# pfctl -nf /etc/pf.conf 解析文件,但不载入
# pfctl -Nf /etc/pf.conf 只载入文件中的NAT规则
# pfctl -Rf /etc/pf.conf 只载入文件中的过滤规则

# pfctl -sn 显示当前的NAT规则
# pfctl -sr 显示当前的过滤规则
# pfctl -ss 显示当前的状态表
# pfctl -si 显示过滤状态和计数
# pfctl -sa 显示任何可显示的

Read more...

Setup a pfSense 2.0 firewall when default gateway is on a different subnet

http://blog.magiksys.net/pfsense-firewall-default-gateway-different-subnet

 

 

I have written a better article, using the firewall in transparent mode here .

This article has been updated for pfSense 2.0. The original article about pfSense 1.2.X has moved here.

News: It looks like the OVH gateway works like an universal ARP proxy or Captive portal. I means my OVH gateway replies to any ARP request. This means that for any given a.b.c.d/32 failover IP, I can setup a host or virtual host using a mask /24 (instead of /32) and my gateway a.b.c.X where X can be anything not in ( 0, 255 or d ) and it will works. And It works, at least on the Kimsufi I have tested it. And it works even for IPs in a.b.c.0/24. I think this is how OVH setup some (maybe all) of their routers to be able to support migration of failover IP or block without too much headache. What is fun is totraceroute some IPs in a.b.c.* and see how they are not directly attached to the WAN but are behind some routers.
OVH don't say anything about this setup and then this feature is funny but cannot be used on a production server.
Be careful if you use a wrong setup and generate a lot of unexpected ARP requests, OVH can warn you to quickly fix the problem or even disable your network link.

If you buy a VMware server and an IP block from OVH you will be surprised because the default gateway don't match the IP block. Even if this setup is unusual, it is valid and give full satisfaction if you know how to configure your firewall and hosts.

There are some advantages to use this technique for the provider/WEB hoster: this make the router configuration a lot simpler (no need to setup an IP address for each underlying IP block, they can merge routes for adjacent IP blocks together) and the most important, this save one IP address in the block.

Windows host accepts this unusual configuration and just work, thanks Bill for this great job .

pf-shellcmd

Linux host requires a little trick.

[root@fc6-pmx ~]# route add default gw 192.168.23.254
SIOCADDRT: Network is unreachable

Linux refuses to add the route because it don't know how to reach the gateway itself. Add the appropriate route for the gateway, before the default route, solves the problem.

[root@fc6-pmx ~]# route add -host 192.168.23.254 dev eth0
[root@fc6-pmx ~]# route add default gw 192.168.23.254

This works !

[root@fc6-pmx ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.23.254  0.0.0.0         255.255.255.255 UH    0      0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.23.254  0.0.0.0         UG    0      0        0 eth0

To configure a firewall, depending of the firewall, you will have to be imaginative !

Differences with the 1.2.X config

The main ideas are the same as in the previous article , but the trick used to connect the gateway is different and finally a lot simpler. I recommend this setup !

Schema

Here is the schema I used to test this configuration.

Network schema

All IPs are from the Address Allocation for Private Internets but it is for testing ! Use the addresses you get from your provider or WEB hoster. For real, only the 172.22.22.1 and 19.168.1.0/24 can be in a private network.

  • 192.168.23.254 is the default gateway given by my provider.
  • 10.0.0.0/24 is the IP block given by my provider. I assign it to my DMZ.
  • 192.168.1.0/24 is a for a virtual LAN, to put machines that help to configure and manage the FW and servers in the DMZ.

The gateway trick

Instead of creating an ARP entry using a command line at startup, I force a route to the gateway by using the route command twice. The trick is the identical to the one used for the Linux in the previousarticle. It is not possible to create such routes using the Web interface then once more the shellcmdmodule come to rescue to setup the route at startup.

To create a route up to 192.168.23.254, on an interface having no IP in this range, I use the commands:

route add -net 192.168.23.254/32 -iface em0
route add default 192.168.23.254  

The first line tell the firewall that IP address 192.168.23.254 is on the side of the em0 interface (em0 is my WAN interface), the second one use this address as the default gateway.

This time, their is no need to found the MAC address of the gateway like in the first article. But some operations like: disable the em0 interface or setup a default gateway; can break the trick and would require to reload the route manually or reboot the firewall.

To remove the route you can use:

route del default 192.168.23.254  
route del -net 192.168.23.254/32 -iface em0

You can create the default route as soon has you have access to the firewall, using ssh, the console or by using the Command prompt in the Diagnostics menu of the Web interface. To be sure the routes are there, click the Routes option in the Diagnostic menu. An look for the two routes.

Routes

Be careful You have to remove any default route before to run these two commands !

This will not give you access to the Internet forthwith, you need some more settings.

The WAN interface

I don't want to waste an IP address, I choose a completely unrelated address 172.22.22.1, and don't setup any gateway because the job is already done by the 2 commands above.

WAN config

The DMZ interface (OPT1)

This is where the servers having a public address live. I give the 10.0.0.1 address to the firewall, this will be the default gateway for servers in the DMZ but also the public IP of the firewall on the WAN side.

DMZ config

The LAN interface

The LAN can be used if you need additional hosts that don't need to be reachable from the Internet but are required to manage the DMZ or for any other purpose. These hosts can access the DMZ (and vice versa when required). This is where I put a virtual machine to configure this firewall. Machines in this zone can be accessed from the Internet too, see later.

LAN config

I keep the default settings of the firewall for this interface.

Setup the Proxy ARP

The 10.0.0.0/24 subnet is on the DMZ side. To allow the firewall to reply to ARP requests for these addresses on the WAN interfaces, we have to add a proxy ARP entry.

Proxy ARP

I do it for the full subnet at once, in previous article I did it address by address. This is faster but also bypass a bug or a feature in 2.0 that forbid the use of an address already used by an interface. I'm thinking here about DMZ address 10.0.0.1. It is possible to go around this by creating the Proxy ARPbefore to assign the address to the DMZ interface. But using a subnet here bypass the problem !

Masquerade the source address

For now, packets leaving the firewall have address 172.22.22.1, replies will never come back ! We need to rewrite the source address for packet leaving the firewall. I use hide NAT to give them the 10.0.0.1address. I assign this address for packet coming from the firewall, but also to masquerade the LAN zone.

Outbound NAT 1

Here are the detail for the LAN, the config for the firewall is similar.

Outbound NAT 2

Now any packets from the firewall or hosts from the LAN will leave the firewall with address 10.0.0.1

Double check the rules for the LAN, and be sure the "Default allow LAN to any rule" permit outgoing connections :

Rules LAN

Don't hesitate to be more strict, for example my second rule block port 25 to the Internet, but not to the DMZ. Here I allow all protocols except some, but the good way when configuring a firewall is to block all traffic by default and permit only some protocols.

The gateway: trick part 2

Now the firewall and the LAN have Internet access, at least after you have setup your DNS. You can now hardcode the gateway trick. You need to install the shellcmd package. The version 0.5 is for pfSense 1.0 but works well with 2.0 too. Install it from the package manager in the System menu!

Package Manager

And in the Service menu, select the Shellcmd option and setup the two commands :

Shellcmd

The DMZ zone (OPT1)

To use your DMZ you have to add filter rules to allow packets to leave the DMZ to the WAN side. Here for outgoing packets...

DMZ outgoing rule

Here I block packets to the LAN, because the DMZ is no more than a part of the Internet itself, any access to the LAN from the DMZ or the Internet must be carefully thought through.

.. and here incoming packets to my public WEB server 10.0.0.2 (the first rule)!

WAN Incoming rule

Create other rules for your other servers and services inside your DMZ !

Because we are using routing we don't need any NAT rules between WAN and DMZ !

LAN has already a full access to the DMZ because of the rule "Default allow LAN to any rule" seen previously. !

The LAN zone

If you need to access some resources inside your LAN from Internet, you can NAT some ports from address 10.0.0.1. Here I forward RDP to my 192.168.1.100 Windows host :

LAN NAT

Double check, pfSense has created the appropriate filter rules.

WAN incoming rules

That'it !

The final touch

Their is lot of other thing to say and to do, but this is not a tutorial about firewall. Anyway I was very impatient to try the new Floating tab in the Rules screen ! I have added a rule to let DMZ hosts reply to ping request. Here it is:

Allows ICMP echo request

Before the Floating tab, you add to duplicate some rules in each interface tab. This was making pfSense 1.2.X a bit unsuitable for configuration with lot of interfaces and rules !

Add IP fail-over

If you need to manage IP fail-over inside this configuration, take a look at this post

Advantages of this configuration

The biggest advantage of this configuration is the use of routing instead of NAT to forward packets. The other are:

  • this config provide a zone for your hosts in your DMZ and your LAN with usual network settings (a gateway in the same LAN subnet).
  • this config is based on routing instead of NAT, this avoid problems with NAT sensible protocol like: ftp, pptp, ...
  • NAT drops connection if no packets are going through for too long. Routing don't and don't require any keep alive plaster!
  • the hosts in your DMZ use the public IP addresses, this make things simple and avoid confusion.
  • LAN access your DMZ using public IP addresses.
  • no need to define NAT rules, only the filter rules are required.
  • reduce the MEMORY and CPU usage of the firewall.

Hope this help !

Read more...

pfsense Enable WAN using shell

* Install pfSense  on your target machine

* Unless your WAN gets a DHCP address, you will need to manually assign the IP Address of the WAN interface:
  --> Get to the CLI (option 8 )
  --> Type "ifconfig en0 10.20.30.40 255.255.255.248" (substitute en0 for your WAN interface and use the correct IP Address/Mask)
  --> Type "route add default <default-gw-ip>"
  --> Type "pfctl -d" to temporarily disable the packet filter

* Point your browser to your WAN IP address then login as admin/pfsense

* Once you have done your initial configuration, MAKE SURE to enable the packet filter again (CLI --> "pfctl -e")

 

 

[2.0-RC1][This email address is being protected from spambots. You need JavaScript enabled to view it.n]/root(1): netstat -rn
Routing tables

Internet:
Destination        Gateway                  Flags    Refs      Use  Netif  Expire
82.53.4.204        link#2                    UHS         0        0    lo0      =>
82.53.4.204/32   link#2                      U           0        0    em1
85.37.17.57        00:0e:0c:dc:c7:d7  UHS         0        2    em1
127.0.0.1            link#5                    UH          0      131    lo0
192.168.0.0/24   link#1                      U           0      384    em0
192.168.0.253    link#1                    UHS         0        0     lo0

 

Read more...
Subscribe to this RSS feed
Notice: Undefined offset: 1 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 18

Notice: Undefined offset: 1 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 34

Notice: Undefined offset: 2 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 34

Notice: Undefined offset: 3 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 34

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/category.php on line 191

Notice: Undefined offset: 1 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 18

Notice: Undefined offset: 1 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 34

Notice: Undefined offset: 2 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 34

Notice: Undefined offset: 3 in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/pagination.php on line 34