CentOS服务器搭建SVN后远程无法连接,请求排查解决
Hey there, let's break down the most likely culprits since you've already nailed the core setup—installation, repo creation, config files, svnserve startup, and port forwarding. Local connectivity working tells us the SVN service itself is healthy, so the problem's almost certainly in the network layer or a tiny config oversight.
Step 1: Verify Server Firewall Rules
CentOS's default firewall (firewalld) blocks incoming connections by default, even if you forwarded the port on your router. Let's make sure port 3690 is open:
- Run these commands to add the port permanently and reload the firewall:
firewall-cmd --add-port=3690/tcp --permanent firewall-cmd --reload - To confirm, check if the port is listed in allowed services:
firewall-cmd --list-ports
If you're using iptables instead of firewalld, add a rule like this:
iptables -A INPUT -p tcp --dport 3690 -j ACCEPT service iptables save
Step 2: Validate Port Forwarding is Working
Router port forwarding can be tricky—let's test if traffic is actually reaching your server:
- On your CentOS server, start a simple listener on port 3690:
nc -lvp 3690 - From a remote machine (not on your local network), run:
nc [your-public-ip] 3690
If the server's nc command shows an incoming connection, port forwarding is good. If not, double-check:
- Did you forward the TCP protocol (SVN uses TCP, not UDP)?
- Is the forwarded port pointing to your server's correct internal IP address (run
ip aon the server to confirm)? - Did you save/apply the router settings and restart the router if needed?
Step 3: Check SVNServe Startup Path & Remote URL
When you start svnserve with -r /path/to/repositories, that sets the root path for all repos. Make sure your remote URL matches this:
- If your repo is at
/var/svn/myrepoand you started svnserve with-r /var/svn, your remote URL should be:svn://[public-ip]/myrepo - If you used the full repo path in
-r, your URL would just besvn://[public-ip]/—but using a parent directory as the root is better for hosting multiple repos.
Step 4: Double-Check svnserve.conf for Hidden Comments
It's easy to miss that lines in svnserve.conf are commented out by default. Ensure these lines have no leading spaces or # characters:
anon-access = none # Or read, if you allow guest access auth-access = write password-db = passwd
Even a single space before these lines will make SVN ignore them—so make sure they're left-aligned and uncommented.
Step 5: Confirm Public IP & DNS (If Using a Domain)
- From a remote machine, check your public IP (you can do this via most search engines by querying "what is my public IP") and confirm it matches the one you're using in your SVN connection URL. If your ISP uses dynamic IPs, the address might have changed since you set up port forwarding.
- If you're using a domain, make sure it resolves to the correct public IP (run
nslookup your-domain.comfrom a remote machine to check).
Step 6: Get Specific Error Messages
Run the SVN info command from a remote machine and note the exact error:
svn info svn://[public-ip]/your-repo-name
- Connection timed out: Almost always a firewall/port forwarding/network routing issue.
- Authentication failed: Check your
passwdfile entries (username:password format, no extra spaces) and ensuresvnserve.confis pointing to the correctpasswdfile path.
Try these steps in order—9 times out of 10, it's either the server firewall blocking the port or a misconfigured router port forward. Let me know if you hit a specific error and we can narrow it down further!
内容的提问来源于stack exchange,提问作者SeanRamey

