# Configure sendmail to use alternate port



## UncleBob (Jul 28, 2009)

Hi, (not sure if I'm posting to the right place thou)

I've been trying to move sendmail from 25 port to something else. I've added the following to the master config:

DAEMON_OPTIONS(`Port=2525, Name=MTA')

Afterwards I compiled new .cf file and restarted sendmail. 

It worked, coz when I telnet to port 2525 I can see sendmail there, but the problem is that it still listens to port 25.

Is there any way to configure sendmail to free port 25?


----------



## DutchDaemon (Jul 28, 2009)

I've tried some alternatives (also involving shutting down the 'submit' side of Sendmail), but it looks like defining 'MTA' anywhere in your .mc file (even with an alternative port) will always open port 25.


----------



## DutchDaemon (Jul 28, 2009)

A last alternative was to omit MTA entirely and take the submit route:

/etc/rc.conf

```
sendmail_submit_enable="YES"
sendmail_enable="NO"
```

sendmail.mc

```
FEATURE(`no_default_msa')
DAEMON_OPTIONS(`Port=2525, Name=MSA, M=E')
```

[cmd=]/etc/rc.d/sendmail forcestart[/cmd]

Result:

```
# sockstat -4p 25      
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
root     sendmail   81354 5  tcp4   *:25                  *:*
root     sendmail   81329 3  tcp4   127.0.0.1:25          *:*
# sockstat -4p 2525
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
root     sendmail   81354 3  tcp4   *:2525                *:*
```

Looks like port 25 is very much hardcoded.


----------



## DutchDaemon (Jul 28, 2009)

Hm, doing it straight up seems to have some result:

/etc/rc.conf

```
sendmail_enable="YES"
sendmail_flags="-L sm-mta -bd -q30m -ODaemonPortOptions=Port=2525"
```

(nothing special in .mc)


```
# sockstat -4p 2525
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
root     sendmail   81578 3  tcp4   *:2525                *:*
# sockstat -4p 25
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
root     sendmail   81329 3  tcp4   127.0.0.1:25          *:*
```

The latter (localhost:25) is needed for handling system email anyway, but your external port 25 will be freed.

If you really want to kill local mail handling:

/etc/rc.conf

```
sendmail_enable="YES"
sendmail_flags="-L sm-mta -bd -q30m -ODaemonPortOptions=Port=2525"
sendmail_submit_enable="NO"
```


----------



## UncleBob (Jul 29, 2009)

Wow,

Thank you for your time! I'll try this approach. 

There will be antispam proxy on external port 25, so I guess localhost:25 is fine to leave for sendmail.


----------



## SirDice (Jul 29, 2009)

UncleBob said:
			
		

> There will be antispam proxy on external port 25, so I guess localhost:25 is fine to leave for sendmail.


In that case simply running sendmail in local-submit-only mode should do. Just have the anti-spam proxy deliver it's mail to localhost:25.

Setting *sendmail_enable="NO"* in /etc/rc.conf will make sendmail run in local-submit-only mode.


----------

