124084f9bSBrian Somers.\" manual page [] for natd 1.4 224084f9bSBrian Somers.Dd 15 April 1997 324084f9bSBrian Somers.Os FreeBSD 424084f9bSBrian Somers.Dt NATD 8 524084f9bSBrian Somers.Sh NAME 624084f9bSBrian Somers.Nm natd 724084f9bSBrian Somers.Nd 824084f9bSBrian SomersNetwork Address Translation Daemon 924084f9bSBrian Somers.Sh SYNOPSIS 1024084f9bSBrian Somers.Nm 1124084f9bSBrian Somers.Op Fl ldsmvu 1224084f9bSBrian Somers.Op Fl permanent_link 1324084f9bSBrian Somers.Op Fl dynamic 1424084f9bSBrian Somers.Op Fl i Ar inport 1524084f9bSBrian Somers.Op Fl o Ar outport 1624084f9bSBrian Somers.Op Fl p Ar port 1724084f9bSBrian Somers.Op Fl a Ar address 1824084f9bSBrian Somers.Op Fl i Ar interface 1924084f9bSBrian Somers.Op Fl f Ar configfile 2024084f9bSBrian Somers 2124084f9bSBrian Somers.Nm 2224084f9bSBrian Somers.Op Fl log 2324084f9bSBrian Somers.Op Fl deny_incoming 2424084f9bSBrian Somers.Op Fl use_sockets 2524084f9bSBrian Somers.Op Fl same_ports 2624084f9bSBrian Somers.Op Fl verbose 2724084f9bSBrian Somers.Op Fl unregistered_only 2824084f9bSBrian Somers.Op Fl permanent_link 2924084f9bSBrian Somers.Op Fl dynamic 3024084f9bSBrian Somers.Op Fl inport Ar inport 3124084f9bSBrian Somers.Op Fl outport Ar outport 3224084f9bSBrian Somers.Op Fl port Ar port 3324084f9bSBrian Somers.Op Fl alias_address Ar address 3424084f9bSBrian Somers.Op Fl interface Ar interface 3524084f9bSBrian Somers.Op Fl config Ar configfile 3624084f9bSBrian Somers 3724084f9bSBrian Somers.Sh DESCRIPTION 3824084f9bSBrian SomersThis program provides a Network Address Translation facility for use 3924084f9bSBrian Somerswith 4024084f9bSBrian Somers.Xr divert 4 4124084f9bSBrian Somerssockets under FreeBSD. Most of the command line options are available 4224084f9bSBrian Somersin a single character short form or in a long form. Use of the long 4324084f9bSBrian Somersform is encouraged as it makes things clearer to the casual observer. 4424084f9bSBrian Somers 4524084f9bSBrian Somers.Pp 4624084f9bSBrian Somers.Nm Natd 4724084f9bSBrian Somersnormally runs in the background as a daemon. It is passed raw IP packets 4824084f9bSBrian Somersas they travel into and out of the machine, and will possibly change these 4924084f9bSBrian Somersbefore re-injecting them back into the IP packet stream. 5024084f9bSBrian Somers 5124084f9bSBrian Somers.Pp 5224084f9bSBrian Somers.Nm Natd 5324084f9bSBrian Somerschanges all packets destined for another host so that their source 5424084f9bSBrian SomersIP number is that of the current machine. For each packet changed 5524084f9bSBrian Somersin this manner, an internal table entry is created to record this 5624084f9bSBrian Somersfact. The source port number is also changed to indicate the 5724084f9bSBrian Somerstable entry applying to the packet. Packets that are received with 5824084f9bSBrian Somersa target IP of the current host are checked against this internal 5924084f9bSBrian Somerstable. If an entry is found, it is used to determine the correct 6024084f9bSBrian Somerstarget IP number and port to place in the packet. 6124084f9bSBrian Somers 6224084f9bSBrian Somers.Pp 6324084f9bSBrian SomersThe following command line options are available. 6424084f9bSBrian Somers.Bl -tag -width Fl 6524084f9bSBrian Somers 6624084f9bSBrian Somers.It Fl log | l 6724084f9bSBrian SomersLog various aliasing statistics and information to the file 6824084f9bSBrian Somers.Pa /var/log/alias.log . 6924084f9bSBrian SomersThis file is truncated each time natd is started. 7024084f9bSBrian Somers 7124084f9bSBrian Somers.It Fl deny_incoming | d 7224084f9bSBrian SomersReject packets destined for the current IP number that have no entry 7324084f9bSBrian Somersin the internal translation table. 7424084f9bSBrian Somers 7524084f9bSBrian Somers.It Fl use_sockets | s 7624084f9bSBrian SomersAllocate a 7724084f9bSBrian Somers.Xr socket 2 7824084f9bSBrian Somersin order to establish an FTP data or IRC DCC send connection. This 7924084f9bSBrian Somersoption uses more system resources, but guarantees successful connections 8024084f9bSBrian Somerswhen port numbers conflict. 8124084f9bSBrian Somers 8224084f9bSBrian Somers.It Fl same_ports | m 8324084f9bSBrian SomersTry to keep the same port number when altering outgoing packets. 8424084f9bSBrian SomersWith this option, protocols such as RPC will have a better chance 8524084f9bSBrian Somersof working. If it is not possible to maintain the port number, it 8624084f9bSBrian Somerswill be silently changed as per normal. 8724084f9bSBrian Somers 8824084f9bSBrian Somers.It Fl verbose | v 8924084f9bSBrian SomersDon't call 9024084f9bSBrian Somers.Xr fork 2 9124084f9bSBrian Somersor 9224084f9bSBrian Somers.Xr daemon 3 9324084f9bSBrian Somerson startup. Instead, stay attached to the controling terminal and 9424084f9bSBrian Somersdisplay all packet alterations to the standard output. This option 9524084f9bSBrian Somersshould only be used for debugging purposes. 9624084f9bSBrian Somers 9724084f9bSBrian Somers.It Fl unregistered_only | u 9824084f9bSBrian SomersOnly alter outgoing packets with an unregistered source address. 9924084f9bSBrian SomersAccording to rfc 1918, unregistered source addresses are 10.0.0.0/8, 10024084f9bSBrian Somers172.16.0.0/12 and 192.168.0.0/16. 10124084f9bSBrian Somers 10224084f9bSBrian Somers.It Fl redirect_port Ar linkspec 10324084f9bSBrian SomersRedirect incoming connections arriving to given port to another host and port. 10424084f9bSBrian SomersLinkspec is of the form 10524084f9bSBrian Somers 10624084f9bSBrian Somers proto targetIP:targetPORT [aliasIP:]aliasPORT [remoteIP[:remotePORT]] 10724084f9bSBrian Somers 10824084f9bSBrian Somerswhere proto is either tcp or udp, targetIP is the desired target IP 10924084f9bSBrian Somersnumber, targetPORT is the desired target PORT number, aliasPORT 11024084f9bSBrian Somersis the requested PORT number and aliasIP is the aliasing address. 11124084f9bSBrian SomersRemoteIP and remotePORT can be used to specify the connection 11224084f9bSBrian Somersmore accurately if necessary. 11324084f9bSBrian SomersFor example, the argument 11424084f9bSBrian Somers 11524084f9bSBrian Somers.Ar tcp inside1:telnet 6666 11624084f9bSBrian Somers 11724084f9bSBrian Somersmeans that tcp packets destined for port 6666 on this machine will 11824084f9bSBrian Somersbe sent to the telnet port on the inside1 machine. 11924084f9bSBrian Somers 12024084f9bSBrian Somers.It Fl redirect_address Ar localIP publicIP 12124084f9bSBrian SomersRedirect traffic for public IP address to a machine on the local 12224084f9bSBrian Somersnetwork. This function is known as "static NAT". Normally static NAT 12324084f9bSBrian Somersis useful if your ISP has allocated a small block of IP addresses to you, 12424084f9bSBrian Somersbut it can even be used in the case of single address: 12524084f9bSBrian Somers 12624084f9bSBrian Somers redirect_address 10.0.0.8 0.0.0.0 12724084f9bSBrian Somers 12824084f9bSBrian SomersThe above command would redirect all incoming traffic 12924084f9bSBrian Somersto machine 10.0.0.8. 13024084f9bSBrian Somers 13124084f9bSBrian SomersIf several address aliases specify the same public address 13224084f9bSBrian Somersas follows 13324084f9bSBrian Somers 13424084f9bSBrian Somers redirect_address 192.168.0.2 public_addr 13524084f9bSBrian Somers redirect_address 192.168.0.3 public_addr 13624084f9bSBrian Somers redirect_address 192.168.0.4 public_addr 13724084f9bSBrian Somers 13824084f9bSBrian Somersthe incoming traffic will be directed to the last 13924084f9bSBrian Somerstranslated local address (192.168.0.4), but outgoing 14024084f9bSBrian Somerstraffice to the first two addresses will still be aliased 14124084f9bSBrian Somersto specified public address. 14224084f9bSBrian Somers 14324084f9bSBrian Somers.It Fl permanent_link Ar linkspec 14424084f9bSBrian SomersCreate a permanent entry in the internal alias table. Linkspec is 14524084f9bSBrian Somersof the form 14624084f9bSBrian Somers 14724084f9bSBrian Somers proto targetIP:targetPORT sourceIP:sourcePORT aliasPORT 14824084f9bSBrian Somers 14924084f9bSBrian Somerswhere proto is either tcp or udp, targetIP is the desired target IP 15024084f9bSBrian Somersnumber, targetPORT is the desired target PORT number, sourceIP and 15124084f9bSBrian SomerssourcePORT match the incoming packet, and aliasPORT is the requested 15224084f9bSBrian SomersPORT number. Values of zero are considered as wildcards. For example, 15324084f9bSBrian Somersthe argument 15424084f9bSBrian Somers 15524084f9bSBrian Somers.Ar tcp inside1:telnet outside1:0 6666 15624084f9bSBrian Somers 15724084f9bSBrian Somersmeans that tcp packets destined for port 6666 on this machine from the 15824084f9bSBrian Somersoutside1 machine (any port) will be sent to the telnet port on the 15924084f9bSBrian Somersinside1 machine. 16024084f9bSBrian Somers 16124084f9bSBrian SomersNew installations are encouraged to use redirect_port instead. 16224084f9bSBrian Somers 16324084f9bSBrian Somers.It Fl dynamic 16424084f9bSBrian SomersIf the 16524084f9bSBrian Somers.Fl n 16624084f9bSBrian Somersor 16724084f9bSBrian Somers.Fl interface 16824084f9bSBrian Somersoption is used, 16924084f9bSBrian Somers.Nm natd 17024084f9bSBrian Somerswill monitor the routing socket for alterations to the 17124084f9bSBrian Somers.Ar interface 17224084f9bSBrian Somerspassed. If the interfaces IP number is changed, 17324084f9bSBrian Somers.Nm natd 17424084f9bSBrian Somerswill dynamically alter its concept of the alias address. 17524084f9bSBrian Somers 17624084f9bSBrian Somers.It Fl i | inport Ar inport 17724084f9bSBrian SomersRead from and write to 17824084f9bSBrian Somers.Ar inport , 17924084f9bSBrian Somerstreating all packets as packets coming into the machine. 18024084f9bSBrian Somers 18124084f9bSBrian Somers.It Fl o | outport Ar outport 18224084f9bSBrian SomersRead from and write to 18324084f9bSBrian Somers.Ar outport , 18424084f9bSBrian Somerstreating all packets as packets going out of the machine. 18524084f9bSBrian Somers 18624084f9bSBrian Somers.It Fl p | port Ar port 18724084f9bSBrian SomersRead from and write to 18824084f9bSBrian Somers.Ar port , 18924084f9bSBrian Somersdistinguishing packets as incoming our outgoing using the rules specified in 19024084f9bSBrian Somers.Xr divert 4 . 19124084f9bSBrian SomersIf 19224084f9bSBrian Somers.Ar port 19324084f9bSBrian Somersis not numeric, it is searched for in the 19424084f9bSBrian Somers.Pa /etc/services 19524084f9bSBrian Somersdatabase using the 19624084f9bSBrian Somers.Xr getservbyname 3 19724084f9bSBrian Somersfunction. If this flag is not specified, the divert port named natd will 19824084f9bSBrian Somersbe used as a default. An example entry in the 19924084f9bSBrian Somers.Pa /etc/services 20024084f9bSBrian Somersdatabase would be: 20124084f9bSBrian Somers 20224084f9bSBrian Somers natd 6668/divert # Network Address Translation socket 20324084f9bSBrian Somers 20424084f9bSBrian SomersRefer to 20524084f9bSBrian Somers.Xr services 5 20624084f9bSBrian Somersfor further details. 20724084f9bSBrian Somers 20824084f9bSBrian Somers.It Fl a | alias_address Ar address 20924084f9bSBrian SomersUse 21024084f9bSBrian Somers.Ar address 21124084f9bSBrian Somersas the alias address. If this option is not specified, the 21224084f9bSBrian Somers.Fl n 21324084f9bSBrian Somersor 21424084f9bSBrian Somers.Fl interface 21524084f9bSBrian Somersoption must be used. 21624084f9bSBrian Somers 21724084f9bSBrian Somers.It Fl n | interface Ar interface 21824084f9bSBrian SomersUse 21924084f9bSBrian Somers.Ar interface 22024084f9bSBrian Somersto determine the alias address. If there is a possibility that the 22124084f9bSBrian SomersIP number associated with 22224084f9bSBrian Somers.Ar interface 22324084f9bSBrian Somersmay change, the 22424084f9bSBrian Somers.Fl dynamic 22524084f9bSBrian Somersflag should also be used. If this option is not specified, the 22624084f9bSBrian Somers.Fl a 22724084f9bSBrian Somersor 22824084f9bSBrian Somers.Fl alias_address 22924084f9bSBrian Somersflag must be used. 23024084f9bSBrian Somers 23124084f9bSBrian Somers.It Fl f | config Ar configfile 23224084f9bSBrian SomersRead configuration from 23324084f9bSBrian Somers.Ar configfile . 23424084f9bSBrian Somers.Ar Configfile 23524084f9bSBrian Somerscontains a list of options, one per line in the same form as the 23624084f9bSBrian Somerslong form of the above command line flags. For example, the line 23724084f9bSBrian Somers 23824084f9bSBrian Somers alias_address 158.152.17.1 23924084f9bSBrian Somers 24024084f9bSBrian Somerswould specify an alias address of 158.152.17.1. Options that don't 24124084f9bSBrian Somerstake an argument are specified with an option of 24224084f9bSBrian Somers.Ar yes 24324084f9bSBrian Somersor 24424084f9bSBrian Somers.Ar no 24524084f9bSBrian Somersin the configuration file. For example, the line 24624084f9bSBrian Somers 24724084f9bSBrian Somers log yes 24824084f9bSBrian Somers 24924084f9bSBrian Somersis synonomous with 25024084f9bSBrian Somers.Fl log . 25124084f9bSBrian SomersEmpty lines and lines beginning with '#' are ignored. 25224084f9bSBrian Somers 25324084f9bSBrian Somers.El 25424084f9bSBrian Somers 25524084f9bSBrian Somers.Sh RUNNING NATD 25624084f9bSBrian SomersThe following steps are necessary before attempting to run 25724084f9bSBrian Somers.Nm natd : 25824084f9bSBrian Somers 25924084f9bSBrian Somers.Bl -enum 26024084f9bSBrian Somers.It 26124084f9bSBrian SomersGet FreeBSD version 2.2 or higher. Versions before this do not support 26224084f9bSBrian Somers.Xr divert 4 26324084f9bSBrian Somerssockets. 26424084f9bSBrian Somers 26524084f9bSBrian Somers.It 26624084f9bSBrian SomersBuild a custom kernel with the following options: 26724084f9bSBrian Somers 26824084f9bSBrian Somers options IPFIREWALL 26924084f9bSBrian Somers options IPDIVERT 27024084f9bSBrian Somers 27124084f9bSBrian SomersRefer to the handbook for detailed instructions on building a custom 27224084f9bSBrian Somerskernel. 27324084f9bSBrian Somers 27424084f9bSBrian Somers.It 27524084f9bSBrian SomersEnsure that your machine is acting as a gateway. This can be done by 27624084f9bSBrian Somersspecifying the line 27724084f9bSBrian Somers 278c1b792b2SJordan K. Hubbard gateway_enable=YES 27924084f9bSBrian Somers 28024084f9bSBrian Somersin 281c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf , 28224084f9bSBrian Somersor using the command 28324084f9bSBrian Somers 28424084f9bSBrian Somers sysctl -w net.inet.ip.forwarding=1 28524084f9bSBrian Somers 28624084f9bSBrian Somers.It 28724084f9bSBrian SomersIf you wish to use the 28824084f9bSBrian Somers.Fl n 28924084f9bSBrian Somersor 29024084f9bSBrian Somers.Fl interface 29124084f9bSBrian Somersflags, make sure that your interface is already configured. If, for 29224084f9bSBrian Somersexample, you wish to specify tun0 as your 29324084f9bSBrian Somers.Ar interface , 29424084f9bSBrian Somersand you're using 29524084f9bSBrian Somers.Xr ppp 8 29624084f9bSBrian Somerson that interface, you must make sure that you start 29724084f9bSBrian Somers.Nm ppp 29824084f9bSBrian Somersprior to starting 29924084f9bSBrian Somers.Nm natd . 30024084f9bSBrian Somers 30124084f9bSBrian Somers.It 30224084f9bSBrian SomersCreate an entry in 30324084f9bSBrian Somers.Pa /etc/services : 30424084f9bSBrian Somers 30524084f9bSBrian Somers natd 6668/divert # Network Address Translation socket 30624084f9bSBrian Somers 30724084f9bSBrian SomersThis gives a default for the 30824084f9bSBrian Somers.Fl p 30924084f9bSBrian Somersor 31024084f9bSBrian Somers.Fl port 31124084f9bSBrian Somersflag. 31224084f9bSBrian Somers 31324084f9bSBrian Somers.El 31424084f9bSBrian Somers.Pp 31524084f9bSBrian SomersRunning 31624084f9bSBrian Somers.Nm natd 31724084f9bSBrian Somersis fairly straight forward. The line 31824084f9bSBrian Somers 31924084f9bSBrian Somers natd -interface ed0 32024084f9bSBrian Somers 32124084f9bSBrian Somersshould suffice in most cases (substituting the correct interface name). Once 32224084f9bSBrian Somers.Nm natd 32324084f9bSBrian Somersis running, you must ensure that traffic is diverted to natd: 32424084f9bSBrian Somers 32524084f9bSBrian Somers.Bl -enum 32624084f9bSBrian Somers.It 32724084f9bSBrian SomersYou will need to adjust the 32824084f9bSBrian Somers.Pa /etc/rc.firewall 32924084f9bSBrian Somersscript to taste. If you're not interested in having a firewall, the 33024084f9bSBrian Somersfollowing lines will do: 33124084f9bSBrian Somers 33224084f9bSBrian Somers /sbin/ipfw -f flush 33324084f9bSBrian Somers /sbin/ipfw add divert 6668 all from any to any via ed0 33424084f9bSBrian Somers /sbin/ipfw add pass all from any to any 33524084f9bSBrian Somers 33624084f9bSBrian SomersThe second line depends on your interface and assumes that you've updated 33724084f9bSBrian Somers.Pa /etc/services 33824084f9bSBrian Somersas above. If you specify real firewall rules, it's best to specify 33924084f9bSBrian Somersline 2 at the start of the script so that 34024084f9bSBrian Somers.Nm natd 34124084f9bSBrian Somerssees all packets before they are dropped by the firewall. The firewall 34224084f9bSBrian Somersrules will be run again on each packet after translation by 34324084f9bSBrian Somers.Nm natd , 34424084f9bSBrian Somersminus any divert rules. 34524084f9bSBrian Somers 34624084f9bSBrian Somers.It 34724084f9bSBrian SomersEnable your firewall by setting 34824084f9bSBrian Somers 34924084f9bSBrian Somers firewall=YES 35024084f9bSBrian Somers 35124084f9bSBrian Somersin 352c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf . 35324084f9bSBrian SomersThis tells the system startup scripts to run the 35424084f9bSBrian Somers.Pa /etc/rc.firewall 35524084f9bSBrian Somersscript. If you don't wish to reboot now, just run this by hand from the 35624084f9bSBrian Somersconsole. NEVER run this from a virtual session unless you put it into 35724084f9bSBrian Somersthe background. If you do, you'll lock yourself out after the flush 35824084f9bSBrian Somerstakes place, and execution of 35924084f9bSBrian Somers.Pa /etc/rc.firewall 36024084f9bSBrian Somerswill stop at this point - blocking all accesses permanently. Running 36124084f9bSBrian Somersthe script in the background should be enough to prevent this disaster. 36224084f9bSBrian Somers 36324084f9bSBrian Somers.El 36424084f9bSBrian Somers 36524084f9bSBrian Somers.Sh SEE ALSO 36624084f9bSBrian Somers.Xr socket 2 , 36724084f9bSBrian Somers.Xr getservbyname 2 , 36824084f9bSBrian Somers.Xr divert 4 , 36924084f9bSBrian Somers.Xr services 5 , 37024084f9bSBrian Somers.Xr ipfw 8 37124084f9bSBrian Somers 37224084f9bSBrian Somers.Sh AUTHORS 37324084f9bSBrian SomersThis program is the result of the efforts of many people at different 37424084f9bSBrian Somerstimes: 37524084f9bSBrian Somers 37624084f9bSBrian Somers Divert sockets: Archie Cobbs <archie@whistle.com> 37724084f9bSBrian Somers Packet aliasing: Charles Mott <cmott@srv.net> 37824084f9bSBrian Somers IRC support & misc additions: Eivind Eklund <eivind@dimaga.com> 37924084f9bSBrian Somers Natd: Ari Suutari <ari.suutari@ps.carel.fi> 38024084f9bSBrian Somers Glue: Brian Somers <brian@awfulhak.org> 381