17f3dea24SPeter Wemm.\" $FreeBSD$ 25a424c8cSRuslan Ermilov.Dd June 27, 2000 324084f9bSBrian Somers.Dt NATD 8 45a424c8cSRuslan Ermilov.Os FreeBSD 524084f9bSBrian Somers.Sh NAME 624084f9bSBrian Somers.Nm natd 75a424c8cSRuslan Ermilov.Nd Network Address Translation Daemon 824084f9bSBrian Somers.Sh SYNOPSIS 95a424c8cSRuslan Ermilov.Nm natd 105a424c8cSRuslan Ermilov.Op Fl unregistered_only | u 115a424c8cSRuslan Ermilov.Op Fl log | l 125a424c8cSRuslan Ermilov.Op Fl proxy_only 135a424c8cSRuslan Ermilov.Op Fl reverse 145a424c8cSRuslan Ermilov.Op Fl deny_incoming | d 155a424c8cSRuslan Ermilov.Op Fl use_sockets | s 165a424c8cSRuslan Ermilov.Op Fl same_ports | m 175a424c8cSRuslan Ermilov.Op Fl verbose | v 1824084f9bSBrian Somers.Op Fl dynamic 195a424c8cSRuslan Ermilov.Op Fl in_port | i Ar port 205a424c8cSRuslan Ermilov.Op Fl out_port | o Ar port 215a424c8cSRuslan Ermilov.Op Fl port | p Ar port 225a424c8cSRuslan Ermilov.Op Fl alias_address | a Ar address 235a424c8cSRuslan Ermilov.Op Fl target_address | t Ar address 245a424c8cSRuslan Ermilov.Op Fl interface | n Ar interface 255a424c8cSRuslan Ermilov.Op Fl proxy_rule Ar proxyspec 2610cffc50SBrian Somers.Op Fl redirect_port Ar linkspec 274330006dSRuslan Ermilov.Op Fl redirect_proto Ar linkspec 28bd690510SRuslan Ermilov.Op Fl redirect_address Ar linkspec 295a424c8cSRuslan Ermilov.Op Fl config | f Ar configfile 305a424c8cSRuslan Ermilov.Op Fl log_denied 315a424c8cSRuslan Ermilov.Op Fl log_facility Ar facility_name 32bc4ebb98SRuslan Ermilov.Op Fl punch_fw Ar firewall_range 3324084f9bSBrian Somers.Sh DESCRIPTION 3424084f9bSBrian SomersThis program provides a Network Address Translation facility for use 3524084f9bSBrian Somerswith 3624084f9bSBrian Somers.Xr divert 4 375a424c8cSRuslan Ermilovsockets under 385a424c8cSRuslan Ermilov.Fx . 395a424c8cSRuslan ErmilovIt is intended for use with NICs - if you want to do NAT on a PPP link, 405a424c8cSRuslan Ermilovuse the 415a424c8cSRuslan Ermilov.Fl nat 425a424c8cSRuslan Ermilovswitch to 4326b4eff6SEivind Eklund.Xr ppp 8 . 4424084f9bSBrian Somers.Pp 455a424c8cSRuslan ErmilovThe 465a424c8cSRuslan Ermilov.Nm 475a424c8cSRuslan Ermilovnormally runs in the background as a daemon. 485a424c8cSRuslan ErmilovIt is passed raw IP packets as they travel into and out of the machine, 495a424c8cSRuslan Ermilovand will possibly change these before re-injecting them back into the 505a424c8cSRuslan ErmilovIP packet stream. 5124084f9bSBrian Somers.Pp 525a424c8cSRuslan ErmilovIt changes all packets destined for another host so that their source 535a424c8cSRuslan ErmilovIP number is that of the current machine. 545a424c8cSRuslan ErmilovFor each packet changed in this manner, an internal table entry is 555a424c8cSRuslan Ermilovcreated to record this fact. 565a424c8cSRuslan ErmilovThe source port number is also changed to indicate the table entry 575a424c8cSRuslan Ermilovapplying to the packet. 585a424c8cSRuslan ErmilovPackets that are received with a target IP of the current host are 595a424c8cSRuslan Ermilovchecked against this internal table. 605a424c8cSRuslan ErmilovIf an entry is found, it is used to determine the correct target IP 615a424c8cSRuslan Ermilovnumber and port to place in the packet. 6224084f9bSBrian Somers.Pp 6324084f9bSBrian SomersThe following command line options are available. 6424084f9bSBrian Somers.Bl -tag -width Fl 6524084f9bSBrian Somers.It Fl log | l 6624084f9bSBrian SomersLog various aliasing statistics and information to the file 6724084f9bSBrian Somers.Pa /var/log/alias.log . 685a424c8cSRuslan ErmilovThis file is truncated each time 695a424c8cSRuslan Ermilov.Nm 705a424c8cSRuslan Ermilovis started. 7124084f9bSBrian Somers.It Fl deny_incoming | d 725a424c8cSRuslan ErmilovDo not pass packets destined for the current IP number that have no 735a424c8cSRuslan Ermiloventry in the internal translation table. 7459a7c613SBrian Somers.It Fl log_denied 755a424c8cSRuslan ErmilovLog denied incoming packets via 765a424c8cSRuslan Ermilov.Xr syslog 3 775a424c8cSRuslan Ermilov.Po 785a424c8cSRuslan Ermilovsee also 795a424c8cSRuslan Ermilov.Fl log_facility 805a424c8cSRuslan Ermilov.Pc . 8159a7c613SBrian Somers.It Fl log_facility Ar facility_name 825a424c8cSRuslan ErmilovUse specified log facility when logging information via 835a424c8cSRuslan Ermilov.Xr syslog 3 . 845a424c8cSRuslan ErmilovArgument 855a424c8cSRuslan Ermilov.Ar facility_name 865a424c8cSRuslan Ermilovis one of the keywords specified in 875a424c8cSRuslan Ermilov.Xr syslog.conf 5 . 8824084f9bSBrian Somers.It Fl use_sockets | s 8924084f9bSBrian SomersAllocate a 9024084f9bSBrian Somers.Xr socket 2 915a424c8cSRuslan Ermilovin order to establish an FTP data or IRC DCC send connection. 925a424c8cSRuslan ErmilovThis option uses more system resources, but guarantees successful 935a424c8cSRuslan Ermilovconnections when port numbers conflict. 9424084f9bSBrian Somers.It Fl same_ports | m 9524084f9bSBrian SomersTry to keep the same port number when altering outgoing packets. 967731ee5aSAlexander LangerWith this option, protocols such as RPC will have a better chance 975a424c8cSRuslan Ermilovof working. 985a424c8cSRuslan ErmilovIf it is not possible to maintain the port number, it will be silently 995a424c8cSRuslan Ermilovchanged as per normal. 10024084f9bSBrian Somers.It Fl verbose | v 1015a424c8cSRuslan ErmilovDo not call 10224084f9bSBrian Somers.Xr daemon 3 1035a424c8cSRuslan Ermilovon startup. 1045a424c8cSRuslan ErmilovInstead, stay attached to the controling terminal and display all packet 1055a424c8cSRuslan Ermilovalterations to the standard output. 1065a424c8cSRuslan ErmilovThis option should only be used for debugging purposes. 10724084f9bSBrian Somers.It Fl unregistered_only | u 1085a424c8cSRuslan ErmilovOnly alter outgoing packets with an 1095a424c8cSRuslan Ermilov.Em unregistered 1105a424c8cSRuslan Ermilovsource address. 1115a424c8cSRuslan ErmilovAccording to RFC 1918, unregistered source addresses are 10.0.0.0/8, 1127731ee5aSAlexander Langer172.16.0.0/12 and 192.168.0.0/16. 1135a424c8cSRuslan Ermilov.It Fl redirect_port Ar proto Xo 1145a424c8cSRuslan Ermilov.Ar targetIP Ns : Ns Xo 1155a424c8cSRuslan Ermilov.Ar targetPORT Ns Op - Ns Ar targetPORT Xc 1165a424c8cSRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo 1175a424c8cSRuslan Ermilov.Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc 1185a424c8cSRuslan Ermilov.Oo Ar remoteIP Ns Oo : Ns 1195a424c8cSRuslan Ermilov.Ar remotePORT Ns Op - Ns Ar remotePORT 1205a424c8cSRuslan Ermilov.Oc Oc 1215a424c8cSRuslan Ermilov.Xc 1229c501140SBrian SomersRedirect incoming connections arriving to given port(s) to another host 1239c501140SBrian Somersand port(s). 1245a424c8cSRuslan ErmilovArgument 1255a424c8cSRuslan Ermilov.Ar proto 1265a424c8cSRuslan Ermilovis either 1275a424c8cSRuslan Ermilov.Ar tcp 1285a424c8cSRuslan Ermilovor 1295a424c8cSRuslan Ermilov.Ar udp , 1305a424c8cSRuslan Ermilov.Ar targetIP 1315a424c8cSRuslan Ermilovis the desired target IP number, 1325a424c8cSRuslan Ermilov.Ar targetPORT 1335a424c8cSRuslan Ermilovis the desired target port number or range, 1345a424c8cSRuslan Ermilov.Ar aliasPORT 1355a424c8cSRuslan Ermilovis the requested port number or range, and 1365a424c8cSRuslan Ermilov.Ar aliasIP 1375a424c8cSRuslan Ermilovis the aliasing address. 1385a424c8cSRuslan ErmilovArguments 1395a424c8cSRuslan Ermilov.Ar remoteIP 1405a424c8cSRuslan Ermilovand 1415a424c8cSRuslan Ermilov.Ar remotePORT 1425a424c8cSRuslan Ermilovcan be used to specify the connection more accurately if necessary. 1435a424c8cSRuslan ErmilovThe 1445a424c8cSRuslan Ermilov.Ar targetPORT 1455a424c8cSRuslan Ermilovrange and 1465a424c8cSRuslan Ermilov.Ar aliasPORT 1475a424c8cSRuslan Ermilovrange need not be the same numerically, but must have the same size. 1485a424c8cSRuslan ErmilovIf 1495a424c8cSRuslan Ermilov.Ar remotePORT 1505a424c8cSRuslan Ermilovis not specified, it is assumed to be all ports. 1515a424c8cSRuslan ErmilovIf 1525a424c8cSRuslan Ermilov.Ar remotePORT 1535a424c8cSRuslan Ermilovis specified, it must match the size of 1545a424c8cSRuslan Ermilov.Ar targetPORT , 1555a424c8cSRuslan Ermilovor be 0 (all ports). 1567731ee5aSAlexander LangerFor example, the argument 1575a424c8cSRuslan Ermilov.Pp 15866648838SBrian Somers.Dl Ar tcp inside1:telnet 6666 1595a424c8cSRuslan Ermilov.Pp 1605a424c8cSRuslan Ermilovmeans that incoming TCP packets destined for port 6666 on this machine 1615a424c8cSRuslan Ermilovwill be sent to the telnet port on the inside1 machine. 1625a424c8cSRuslan Ermilov.Pp 16366648838SBrian Somers.Dl Ar tcp inside2:2300-2399 3300-3399 1645a424c8cSRuslan Ermilov.Pp 1659c501140SBrian Somerswill redirect incoming connections on ports 3300-3399 to host 1669c501140SBrian Somersinside2, ports 2300-2399. 1679c501140SBrian SomersThe mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc. 1685a424c8cSRuslan Ermilov.It Fl redirect_proto Ar proto localIP Oo 1695a424c8cSRuslan Ermilov.Ar publicIP Op Ar remoteIP 1705a424c8cSRuslan Ermilov.Oc 1714330006dSRuslan ErmilovRedirect incoming IP packets of protocol 1724330006dSRuslan Ermilov.Ar proto 1735a424c8cSRuslan Ermilov.Po see Xr protocols 5 1745a424c8cSRuslan Ermilov.Pc 1754330006dSRuslan Ermilovdestined for 1764330006dSRuslan Ermilov.Ar publicIP 1774330006dSRuslan Ermilovaddress to a 1784330006dSRuslan Ermilov.Ar localIP 1794330006dSRuslan Ermilovaddress and vice versa. 1804330006dSRuslan Ermilov.Pp 1814330006dSRuslan ErmilovIf 1824330006dSRuslan Ermilov.Ar publicIP 1837731ee5aSAlexander Langeris not specified, then the default aliasing address is used. 1844330006dSRuslan ErmilovIf 1854330006dSRuslan Ermilov.Ar remoteIP 1867731ee5aSAlexander Langeris specified, then only packets coming from/to 1874330006dSRuslan Ermilov.Ar remoteIP 1884330006dSRuslan Ermilovwill match the rule. 18924084f9bSBrian Somers.It Fl redirect_address Ar localIP publicIP 1907731ee5aSAlexander LangerRedirect traffic for public IP address to a machine on the local 1917731ee5aSAlexander Langernetwork. 1925a424c8cSRuslan ErmilovThis function is known as 1935a424c8cSRuslan Ermilov.Em static NAT . 1945a424c8cSRuslan ErmilovNormally static NAT is useful if your ISP has allocated a small block 1955a424c8cSRuslan Ermilovof IP addresses to you, but it can even be used in the case of single 1965a424c8cSRuslan Ermilovaddress: 1975a424c8cSRuslan Ermilov.Pp 1985a424c8cSRuslan Ermilov.Dl Ar redirect_address 10.0.0.8 0.0.0.0 1995a424c8cSRuslan Ermilov.Pp 2007731ee5aSAlexander LangerThe above command would redirect all incoming traffic 2017731ee5aSAlexander Langerto machine 10.0.0.8. 2025a424c8cSRuslan Ermilov.Pp 2037731ee5aSAlexander LangerIf several address aliases specify the same public address 2047731ee5aSAlexander Langeras follows 2055a424c8cSRuslan Ermilov.Bd -literal -offset indent 2065a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.2 public_addr 2075a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.3 public_addr 2085a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.4 public_addr 2095a424c8cSRuslan Ermilov.Ed 2105a424c8cSRuslan Ermilov.Pp 21124084f9bSBrian Somersthe incoming traffic will be directed to the last 2127731ee5aSAlexander Langertranslated local address (192.168.0.4), but outgoing 2135a424c8cSRuslan Ermilovtraffic from the first two addresses will still be aliased 2145a424c8cSRuslan Ermilovto appear from the specified 2155a424c8cSRuslan Ermilov.Ar public_addr . 216bd690510SRuslan Ermilov.It Fl redirect_port Ar proto Xo 217bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo 218bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns 219bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo 220bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns 221bd690510SRuslan Ermilov.Ar ... 222bd690510SRuslan Ermilov.Oc Oc 223bd690510SRuslan Ermilov.Xc 224bd690510SRuslan Ermilov.Xc 225bd690510SRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo 226bd690510SRuslan Ermilov.Ar aliasPORT 227bd690510SRuslan Ermilov.Xc 228bd690510SRuslan Ermilov.Oo Ar remoteIP Ns 229bd690510SRuslan Ermilov.Op : Ns Ar remotePORT 230bd690510SRuslan Ermilov.Oc 231bd690510SRuslan Ermilov.Xc 232bd690510SRuslan Ermilov.It Fl redirect_address Xo 233bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns 234bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns 235bd690510SRuslan Ermilov.Ar ... 236bd690510SRuslan Ermilov.Oc Oc 237bd690510SRuslan Ermilov.Ar publicIP 238bd690510SRuslan Ermilov.Xc 239bd690510SRuslan ErmilovThese forms of 240bd690510SRuslan Ermilov.Fl redirect_port 241bd690510SRuslan Ermilovand 242bd690510SRuslan Ermilov.Fl redirect_address 243bd690510SRuslan Ermilovare used to transparently offload network load on a single server and 244bd690510SRuslan Ermilovdistribute the load across a pool of servers. 245bd690510SRuslan ErmilovThis function is known as 246bd690510SRuslan Ermilov.Em LSNAT 247bd690510SRuslan Ermilov(RFC 2391). 2487731ee5aSAlexander LangerFor example, the argument 249bd690510SRuslan Ermilov.Pp 250bd690510SRuslan Ermilov.Dl Ar tcp www1:http,www2:http,www3:http www:http 251bd690510SRuslan Ermilov.Pp 252bd690510SRuslan Ermilovmeans that incoming HTTP requests for host www will be transparently 2537731ee5aSAlexander Langerredirected to one of the www1, www2 or www3, where a host is selected 2547731ee5aSAlexander Langersimply on a round-robin basis, without regard to load on the net. 25524084f9bSBrian Somers.It Fl dynamic 25624084f9bSBrian SomersIf the 25724084f9bSBrian Somers.Fl n 25824084f9bSBrian Somersor 25924084f9bSBrian Somers.Fl interface 26024084f9bSBrian Somersoption is used, 2610fc81af1SPhilippe Charnier.Nm 26224084f9bSBrian Somerswill monitor the routing socket for alterations to the 26324084f9bSBrian Somers.Ar interface 2645a424c8cSRuslan Ermilovpassed. 2655a424c8cSRuslan ErmilovIf the interface's IP number is changed, 2660fc81af1SPhilippe Charnier.Nm 26724084f9bSBrian Somerswill dynamically alter its concept of the alias address. 2685a424c8cSRuslan Ermilov.It Fl in_port | i Ar port 26924084f9bSBrian SomersRead from and write to 27024084f9bSBrian Somers.Ar port , 2715a424c8cSRuslan Ermilovtreating all packets as packets coming into the machine. 2725a424c8cSRuslan Ermilov.It Fl out_port | o Ar port 2735a424c8cSRuslan ErmilovRead from and write to 2745a424c8cSRuslan Ermilov.Ar port , 2755a424c8cSRuslan Ermilovtreating all packets as packets going out of the machine. 2765a424c8cSRuslan Ermilov.It Fl port | p Ar port 2775a424c8cSRuslan ErmilovRead from and write to 2785a424c8cSRuslan Ermilov.Ar port , 2795a424c8cSRuslan Ermilovdistinguishing packets as incoming our outgoing using the rules 2805a424c8cSRuslan Ermilovspecified in 28124084f9bSBrian Somers.Xr divert 4 . 28224084f9bSBrian SomersIf 28324084f9bSBrian Somers.Ar port 28424084f9bSBrian Somersis not numeric, it is searched for in the 28524084f9bSBrian Somers.Xr services 5 2865a424c8cSRuslan Ermilovdatabase. 2875a424c8cSRuslan ErmilovIf this option is not specified, the divert port named 2885a424c8cSRuslan Ermilov.Em natd 2895a424c8cSRuslan Ermilovwill be used as a default. 2905a424c8cSRuslan Ermilov.It Fl alias_address | a Ar address 29124084f9bSBrian SomersUse 29224084f9bSBrian Somers.Ar address 2935a424c8cSRuslan Ermilovas the aliasing address. 2945a424c8cSRuslan ErmilovIf this option is not specified, the 29524084f9bSBrian Somers.Fl interface 2965a424c8cSRuslan Ermilovoption must be used. 2975a424c8cSRuslan ErmilovThe specified address is usually the address assigned to the 2985a424c8cSRuslan Ermilovpublic network interface. 299f7d1db72SBrian Somers.Pp 3005a424c8cSRuslan ErmilovAll data passing 3015a424c8cSRuslan Ermilov.Em out 3025a424c8cSRuslan Ermilovwill be rewritten with a source address equal to 303f7d1db72SBrian Somers.Ar address . 3045a424c8cSRuslan ErmilovAll data coming 3055a424c8cSRuslan Ermilov.Em in 3065a424c8cSRuslan Ermilovwill be checked to see if it matches any already-aliased outgoing 3075a424c8cSRuslan Ermilovconnection. 3085a424c8cSRuslan ErmilovIf it does, the packet is altered accordingly. 3095a424c8cSRuslan ErmilovIf not, all 3105a424c8cSRuslan Ermilov.Fl redirect_port , 3115a424c8cSRuslan Ermilov.Fl redirect_proto 312f7d1db72SBrian Somersand 313f7d1db72SBrian Somers.Fl redirect_address 3145a424c8cSRuslan Ermilovassignments are checked and actioned. 3155a424c8cSRuslan ErmilovIf no other action can be made and if 316f7d1db72SBrian Somers.Fl deny_incoming 3175a424c8cSRuslan Ermilovis not specified, the packet is delivered unaltered to the local 3185a424c8cSRuslan Ermilovmachine and port as specified in the packet, but see the 3195a424c8cSRuslan Ermilov.Fl target_address 3205a424c8cSRuslan Ermilovoption below. 32111c2b3bfSRuslan Ermilov.It Fl t | target_address Ar address 32211c2b3bfSRuslan ErmilovSet the target address. 32311c2b3bfSRuslan ErmilovWhen an incoming packet not associated with any pre-existing link 3247731ee5aSAlexander Langerarrives at the host machine, it will be sent to the specified 32511c2b3bfSRuslan Ermilov.Ar address . 32611c2b3bfSRuslan Ermilov.Pp 32711c2b3bfSRuslan ErmilovThe target address may be set to 3285a424c8cSRuslan Ermilov.Ar 255.255.255.255 , 32911c2b3bfSRuslan Ermilovin which case all new incoming packets go to the alias address set by 33011c2b3bfSRuslan Ermilov.Fl alias_address 33111c2b3bfSRuslan Ermilovor 33211c2b3bfSRuslan Ermilov.Fl interface . 33311c2b3bfSRuslan Ermilov.Pp 3347731ee5aSAlexander LangerIf this option is not used, or called with the argument 3355a424c8cSRuslan Ermilov.Ar 0.0.0.0 , 3367731ee5aSAlexander Langerthen all new incoming packets go to the address specified in 3377731ee5aSAlexander Langerthe packet. 33811c2b3bfSRuslan ErmilovThis allows external machines to talk directly to internal machines if 33911c2b3bfSRuslan Ermilovthey can route packets to the machine in question. 3405a424c8cSRuslan Ermilov.It Fl interface | n Ar interface 34124084f9bSBrian SomersUse 34224084f9bSBrian Somers.Ar interface 3435a424c8cSRuslan Ermilovto determine the aliasing address. 3445a424c8cSRuslan ErmilovIf there is a possibility that the IP number associated with 34524084f9bSBrian Somers.Ar interface 34624084f9bSBrian Somersmay change, the 34724084f9bSBrian Somers.Fl dynamic 3485a424c8cSRuslan Ermilovoption should also be used. 3495a424c8cSRuslan ErmilovIf this option is not specified, the 35024084f9bSBrian Somers.Fl alias_address 3515a424c8cSRuslan Ermilovoption must be used. 352f7d1db72SBrian Somers.Pp 353f7d1db72SBrian SomersThe specified 354f7d1db72SBrian Somers.Ar interface 3555a424c8cSRuslan Ermilovis usually the public network interface. 3565a424c8cSRuslan Ermilov.It Fl config | f Ar file 35724084f9bSBrian SomersRead configuration from 3585a424c8cSRuslan Ermilov.Ar file . 3595a424c8cSRuslan ErmilovA 3605a424c8cSRuslan Ermilov.Ar file 3615a424c8cSRuslan Ermilovshould contain a list of options, one per line, in the same form 3625a424c8cSRuslan Ermilovas the long form of the above command line options. 3635a424c8cSRuslan ErmilovFor example, the line 3645a424c8cSRuslan Ermilov.Pp 3655a424c8cSRuslan Ermilov.Dl alias_address 158.152.17.1 3665a424c8cSRuslan Ermilov.Pp 3675a424c8cSRuslan Ermilovwould specify an alias address of 158.152.17.1. 3685a424c8cSRuslan ErmilovOptions that do not take an argument are specified with an option of 36924084f9bSBrian Somers.Ar yes 37024084f9bSBrian Somersor 37124084f9bSBrian Somers.Ar no 3725a424c8cSRuslan Ermilovin the configuration file. 3735a424c8cSRuslan ErmilovFor example, the line 3745a424c8cSRuslan Ermilov.Pp 3755a424c8cSRuslan Ermilov.Dl log yes 3765a424c8cSRuslan Ermilov.Pp 3775a424c8cSRuslan Ermilovis synonymous with 37824084f9bSBrian Somers.Fl log . 3792e7e7c71SRuslan Ermilov.Pp 3802e7e7c71SRuslan ErmilovTrailing spaces and empty lines are ignored. 3812e7e7c71SRuslan ErmilovA 3822e7e7c71SRuslan Ermilov.Ql \&# 3832522beceSMike Pritchardsign will mark the rest of the line as a comment. 38459a7c613SBrian Somers.It Fl reverse 3855a424c8cSRuslan ErmilovThis option makes 3865a424c8cSRuslan Ermilov.Nm 3875a424c8cSRuslan Ermilovreverse the way it handles incoming and outgoing packets, 3885a424c8cSRuslan Ermilovallowing it to operate on the internal interface rather than 3895a424c8cSRuslan Ermilovthe external one. 3905a424c8cSRuslan Ermilov.Pp 3915a424c8cSRuslan ErmilovThis can be useful in some transparent proxying situations 3925a424c8cSRuslan Ermilovwhen outgoing traffic is redirected to the local machine 3935a424c8cSRuslan Ermilovand 3945a424c8cSRuslan Ermilov.Nm 3955a424c8cSRuslan Ermilovis running on the internal interface (it usually runs on the 3965a424c8cSRuslan Ermilovexternal interface). 39759a7c613SBrian Somers.It Fl proxy_only 3985a424c8cSRuslan ErmilovForce 3995a424c8cSRuslan Ermilov.Nm 4005a424c8cSRuslan Ermilovto perform transparent proxying only. 401ef8f7ac9SSheldon HearnNormal address translation is not performed. 4025a424c8cSRuslan Ermilov.It Fl proxy_rule Xo 4035a424c8cSRuslan Ermilov.Op Ar type encode_ip_hdr | encode_tcp_stream 4045a424c8cSRuslan Ermilov.Ar port xxxx 4055a424c8cSRuslan Ermilov.Ar server a.b.c.d:yyyy 4065a424c8cSRuslan Ermilov.Xc 407ef8f7ac9SSheldon HearnEnable transparent proxying. 4085a424c8cSRuslan ErmilovOutgoing TCP packets with the given port going through this 4097731ee5aSAlexander Langerhost to any other host are redirected to the given server and port. 410ef8f7ac9SSheldon HearnOptionally, the original target address can be encoded into the packet. 411ef8f7ac9SSheldon HearnUse 4125a424c8cSRuslan Ermilov.Ar encode_ip_hdr 41359a7c613SBrian Somersto put this information into the IP option field or 4145a424c8cSRuslan Ermilov.Ar encode_tcp_stream 41559a7c613SBrian Somersto inject the data into the beginning of the TCP stream. 416bc4ebb98SRuslan Ermilov.It Fl punch_fw Xo 417bc4ebb98SRuslan Ermilov.Ar basenumber Ns : Ns Ar count 418bc4ebb98SRuslan Ermilov.Xc 419f685a909SRuslan ErmilovThis option directs 420bc4ebb98SRuslan Ermilov.Nm 421f685a909SRuslan Ermilovto 422f685a909SRuslan Ermilov.Dq punch holes 423bc4ebb98SRuslan Ermilovin an 424bc4ebb98SRuslan Ermilov.Xr ipfirewall 4 425bc4ebb98SRuslan Ermilovbased firewall for FTP/IRC DCC connections. 426f685a909SRuslan ErmilovThis is done dynamically by installing temporary firewall rules which 427f685a909SRuslan Ermilovallow a particular connection (and only that connection) to go through 428f685a909SRuslan Ermilovthe firewall. 429f685a909SRuslan ErmilovThe rules are removed once the corresponding connection terminates. 430bc4ebb98SRuslan Ermilov.Pp 431f685a909SRuslan ErmilovA maximum of 432bc4ebb98SRuslan Ermilov.Ar count 433f685a909SRuslan Ermilovrules starting from the rule number 434f685a909SRuslan Ermilov.Ar basenumber 435f685a909SRuslan Ermilovwill be used for punching firewall holes. 436bc4ebb98SRuslan ErmilovThe range will be cleared for all rules on startup. 43724084f9bSBrian Somers.El 43824084f9bSBrian Somers.Sh RUNNING NATD 43924084f9bSBrian SomersThe following steps are necessary before attempting to run 44024084f9bSBrian Somers.Nm natd : 44124084f9bSBrian Somers.Bl -enum 44224084f9bSBrian Somers.It 44324084f9bSBrian SomersBuild a custom kernel with the following options: 4445a424c8cSRuslan Ermilov.Bd -literal -offset indent 44524084f9bSBrian Somersoptions IPFIREWALL 44624084f9bSBrian Somersoptions IPDIVERT 4475a424c8cSRuslan Ermilov.Ed 4485a424c8cSRuslan Ermilov.Pp 44924084f9bSBrian SomersRefer to the handbook for detailed instructions on building a custom 45024084f9bSBrian Somerskernel. 45124084f9bSBrian Somers.It 4525a424c8cSRuslan ErmilovEnsure that your machine is acting as a gateway. 4535a424c8cSRuslan ErmilovThis can be done by specifying the line 4545a424c8cSRuslan Ermilov.Pp 4555a424c8cSRuslan Ermilov.Dl gateway_enable=YES 4565a424c8cSRuslan Ermilov.Pp 4575a424c8cSRuslan Ermilovin the 4585a424c8cSRuslan Ermilov.Pa /etc/rc.conf 4595a424c8cSRuslan Ermilovfile or using the command 4605a424c8cSRuslan Ermilov.Pp 4615a424c8cSRuslan Ermilov.Dl sysctl -w net.inet.ip.forwarding=1 4625a424c8cSRuslan Ermilov.Pp 46324084f9bSBrian Somers.It 4645a424c8cSRuslan ErmilovIf you use the 46524084f9bSBrian Somers.Fl interface 4665a424c8cSRuslan Ermilovoption, make sure that your interface is already configured. 4675a424c8cSRuslan ErmilovIf, for example, you wish to specify tun0 as your 46824084f9bSBrian Somers.Ar interface , 4695a424c8cSRuslan Ermilovand you are using 47024084f9bSBrian Somers.Xr ppp 8 4717731ee5aSAlexander Langeron that interface, you must make sure that you start 47224084f9bSBrian Somers.Nm ppp 47324084f9bSBrian Somersprior to starting 47424084f9bSBrian Somers.Nm natd . 47524084f9bSBrian Somers.El 47624084f9bSBrian Somers.Pp 47724084f9bSBrian SomersRunning 4780fc81af1SPhilippe Charnier.Nm 4795a424c8cSRuslan Ermilovis fairly straight forward. 4805a424c8cSRuslan ErmilovThe line 4815a424c8cSRuslan Ermilov.Pp 4825a424c8cSRuslan Ermilov.Dl natd -interface ed0 4835a424c8cSRuslan Ermilov.Pp 4845a424c8cSRuslan Ermilovshould suffice in most cases (substituting the correct interface name). 4855a424c8cSRuslan ErmilovOnce 4860fc81af1SPhilippe Charnier.Nm 4875a424c8cSRuslan Ermilovis running, you must ensure that traffic is diverted to 4885a424c8cSRuslan Ermilov.Nm natd : 48924084f9bSBrian Somers.Bl -enum 49024084f9bSBrian Somers.It 49124084f9bSBrian SomersYou will need to adjust the 49224084f9bSBrian Somers.Pa /etc/rc.firewall 4935a424c8cSRuslan Ermilovscript to taste. 4945a424c8cSRuslan ErmilovIf you are not interested in having a firewall, the 49524084f9bSBrian Somersfollowing lines will do: 4965a424c8cSRuslan Ermilov.Bd -literal -offset indent 49724084f9bSBrian Somers/sbin/ipfw -f flush 49846b2c559SBrian Somers/sbin/ipfw add divert natd all from any to any via ed0 49924084f9bSBrian Somers/sbin/ipfw add pass all from any to any 5005a424c8cSRuslan Ermilov.Ed 5015a424c8cSRuslan Ermilov.Pp 5025a424c8cSRuslan ErmilovThe second line depends on your interface (change ed0 as appropriate). 5035a424c8cSRuslan Ermilov.Pp 5045a424c8cSRuslan ErmilovYou should be aware of the fact that, with these firewall settings, 5055a424c8cSRuslan Ermiloveveryone on your local network can fake his source-address using your 5065a424c8cSRuslan Ermilovhost as gateway. 5075a424c8cSRuslan ErmilovIf there are other hosts on your local network, you are strongly 5085a424c8cSRuslan Ermilovencouraged to create firewall rules that only allow traffic to and 5095a424c8cSRuslan Ermilovfrom trusted hosts. 5105a424c8cSRuslan Ermilov.Pp 5115a424c8cSRuslan ErmilovIf you specify real firewall rules, it is best to specify line 2 at 5125a424c8cSRuslan Ermilovthe start of the script so that 5130fc81af1SPhilippe Charnier.Nm 51404bf7dcfSRuslan Ermilovsees all packets before they are dropped by the firewall. 51504bf7dcfSRuslan Ermilov.Pp 51604bf7dcfSRuslan ErmilovAfter translation by 51724084f9bSBrian Somers.Nm natd , 51804bf7dcfSRuslan Ermilovpackets re-enter the firewall at the rule number following the rule number 5197731ee5aSAlexander Langerthat caused the diversion (not the next rule if there are several at the 5207731ee5aSAlexander Langersame number). 52124084f9bSBrian Somers.It 52224084f9bSBrian SomersEnable your firewall by setting 5235a424c8cSRuslan Ermilov.Pp 5245a424c8cSRuslan Ermilov.Dl firewall_enable=YES 5255a424c8cSRuslan Ermilov.Pp 52624084f9bSBrian Somersin 527c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf . 52824084f9bSBrian SomersThis tells the system startup scripts to run the 52924084f9bSBrian Somers.Pa /etc/rc.firewall 5305a424c8cSRuslan Ermilovscript. 5315a424c8cSRuslan ErmilovIf you do not wish to reboot now, just run this by hand from the console. 5325a424c8cSRuslan ErmilovNEVER run this from a remote session unless you put it into the background. 5335a424c8cSRuslan ErmilovIf you do, you will lock yourself out after the flush takes place, and 5345a424c8cSRuslan Ermilovexecution of 53524084f9bSBrian Somers.Pa /etc/rc.firewall 5365a424c8cSRuslan Ermilovwill stop at this point - blocking all accesses permanently. 5375a424c8cSRuslan ErmilovRunning the script in the background should be enough to prevent this 5385a424c8cSRuslan Ermilovdisaster. 53924084f9bSBrian Somers.El 54024084f9bSBrian Somers.Sh SEE ALSO 54124084f9bSBrian Somers.Xr divert 4 , 5425a424c8cSRuslan Ermilov.Xr protocols 5 , 5435a424c8cSRuslan Ermilov.Xr rc.conf 5 , 54424084f9bSBrian Somers.Xr services 5 , 5455a424c8cSRuslan Ermilov.Xr syslog.conf 5 , 5465a424c8cSRuslan Ermilov.Xr ipfw 8 , 5475a424c8cSRuslan Ermilov.Xr ppp 8 . 54824084f9bSBrian Somers.Sh AUTHORS 54924084f9bSBrian SomersThis program is the result of the efforts of many people at different 55024084f9bSBrian Somerstimes: 5515a424c8cSRuslan Ermilov.Pp 552f12a1471SPhilippe Charnier.An Archie Cobbs Aq archie@whistle.com 553f12a1471SPhilippe Charnier(divert sockets) 5547ffac027SBrian Somers.An Charles Mott Aq cmott@scientech.com 555f12a1471SPhilippe Charnier(packet aliasing) 556f12a1471SPhilippe Charnier.An Eivind Eklund Aq perhaps@yes.no 557f12a1471SPhilippe Charnier(IRC support & misc additions) 558f12a1471SPhilippe Charnier.An Ari Suutari Aq suutari@iki.fi 559f12a1471SPhilippe Charnier(natd) 56059a7c613SBrian Somers.An Dru Nelson Aq dnelson@redwoodsoft.com 561dc1a0225SRuslan Ermilov(early PPTP support) 562f12a1471SPhilippe Charnier.An Brian Somers Aq brian@awfulhak.org 563f12a1471SPhilippe Charnier(glue) 564