如何让局域网内其他机器使用本机的Postfix邮件服务(CCDC)
Hey there! As someone prepping for CCDC with a Postfix server on Ubuntu, let's get this sorted so all your team's LAN machines can send and receive emails through your host. Since you already have Postfix installed, we just need to tweak a few key configurations:
1. Update Postfix Listening Interfaces
By default, Postfix might only listen on localhost, which blocks LAN connections. Let's change that:
- Open the main config file with:
sudo nano /etc/postfix/main.cf - Find the
inet_interfacesline and update it to either:inet_interfaces = all(listens on all available network interfaces)- Or specify your Ubuntu host's LAN IP explicitly:
inet_interfaces = 127.0.0.1, 192.168.x.x(replace192.168.x.xwith your actual static LAN IP)
- Make sure
inet_protocolsis set toipv4(orallif you use IPv6) to avoid connectivity issues.
2. Allow LAN Clients to Connect
Postfix uses the mynetworks setting to define trusted IP ranges that can send emails without authentication (perfect for your closed CCDC LAN):
- In the same
main.cffile, locatemynetworksand update it to include your LAN subnet. For example:
Replacemynetworks = 127.0.0.0/8, 192.168.1.0/24192.168.1.0/24with your team's actual LAN subnet (e.g.,10.0.0.0/24if that's your CCDC network range).
3. Configure Local Email Destinations
Ensure Postfix recognizes emails addressed to your LAN domain or server hostname:
- Find the
mydestinationline inmain.cfand add your server's local hostname or domain. For example:
Replacemydestination = $myhostname, localhost.$mydomain, localhost, mail-server.localmail-server.localwith your server's actual hostname (check withhostnamecommand).
4. Restart Postfix & Verify
Save your changes to main.cf (Ctrl+O, then Ctrl+X in nano) and restart the service to apply updates:
sudo systemctl restart postfix- Check if Postfix is running correctly:
sudo systemctl status postfix
You should see "active (running)" in the output.
5. Open Firewall for SMTP
Ubuntu's default UFW firewall might block port 25 (SMTP), so let's allow it for LAN traffic:
sudo ufw allow 25/tcp
6. Test LAN Email Functionality
Grab another machine on the LAN to test sending an email:
- On a Linux client:
echo "This is a test email from the LAN" | mail -s "CCDC Postfix Test" your-username@mail-server.local -S smtp=smtp://192.168.x.x - On a Windows client (PowerShell):
ReplaceSend-MailMessage -From "team-member@client.local" -To "your-username@mail-server.local" -SmtpServer "192.168.x.x" -Subject "CCDC Postfix Test" -Body "This is a test from Windows!"192.168.x.xwith your Postfix server's LAN IP, and adjust email addresses to match your setup.
Quick CCDC Tips
- Set a static LAN IP for your Postfix server so team members don't lose connectivity if the IP changes.
- If you need to retrieve emails (not just send), install Dovecot for POP3/IMAP access—this lets clients like Thunderbird fetch emails from the server.
- Keep an eye on Postfix logs (
/var/log/mail.log) if you run into issues—they'll help troubleshoot connection or delivery problems fast.
内容的提问来源于stack exchange,提问作者Chad

