How to Change Port for Jenkins?

Jenkins is an open-source automation server that helps developers build, test, and deploy their software. When installed, Jenkins uses port 8080 by default to listen for HTTP requests. However, this port may conflict with other applications or not meet your environment's security requirements, making it necessary to change the port number.

Understanding Ports in Jenkins

A port is a virtual communication endpoint that allows applications to exchange data over a network. Ports are numbered from 0 to 65535, with specific numbers reserved for particular services (e.g., port 80 for HTTP, port 443 for HTTPS).

Common Jenkins Ports

  • HTTP Port (default: 8080) Main port for serving the Jenkins web interface

  • AJP Port (default: disabled) Apache JServ Protocol port for web server communication

  • JNLP Port (default: random) Java Network Launch Protocol port for Jenkins agent connections

How to Change Jenkins Port

The process varies depending on your Jenkins installation method and operating system.

Method 1: Jenkins Service Configuration (Windows/Linux)

Step 1: Locate the Jenkins installation directory

  • Linux: /var/lib/jenkins or /etc/default/jenkins

  • Windows: C:\Program Files (x86)\Jenkins

Step 2: Navigate to the Jenkins directory and locate the configuration file

cd /var/lib/jenkins
ls

Step 3: Edit the jenkins.xml file (Windows) or Jenkins configuration file (Linux)

sudo vim jenkins.xml

Step 4: Find the <arguments> section and locate the port parameter

--httpPort=8080

Step 5: Change the port number to your desired value

--httpPort=9090

Step 6: Save the file and restart Jenkins

sudo service jenkins restart

Method 2: Command Line Parameter

You can also start Jenkins with a custom port using the command line:

java -jar jenkins.war --httpPort=9090

Method 3: Environment Variable (Linux)

On Linux systems, edit the Jenkins configuration file:

sudo vim /etc/default/jenkins

Modify or add the following line:

HTTP_PORT=9090

Troubleshooting Common Issues

Issue Cause Solution
Port already in use Another application is using the port Choose a different port number
Cannot access Jenkins Firewall blocking the new port Update firewall rules to allow traffic
Service won't start Invalid port number or syntax error Verify configuration syntax and port range

Best Practices

  • Choose unused ports: Use netstat -tuln to check available ports

  • Document changes: Keep record of custom port configurations

  • Update firewall rules: Ensure the new port is accessible through firewalls

  • Use non-standard ports: Avoid well-known ports (0-1023) for security

  • Enable SSL: Consider using HTTPS with custom ports for enhanced security

Verification

After changing the port, verify Jenkins is accessible by opening a web browser and navigating to:

http://localhost:9090

Replace 9090 with your chosen port number.

Conclusion

Changing the Jenkins port is straightforward and involves modifying configuration files or using command-line parameters. Always choose unused ports, update firewall settings, and document your changes. This simple modification can resolve port conflicts and improve your Jenkins deployment's security and accessibility.

Updated on: 2026-03-17T09:01:39+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements