How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?
3 Answers
Several connectors are configured, and each connector has an optional "address" attribute where you can set the IP address.
- Edit
tomcat/conf/server.xml
. - Specify a bind address for that connector:
<Connector port="8080" protocol="HTTP/1.1" address="127.0.0.1" connectionTimeout="20000" redirectPort="8443" />

- 30,436
- 41
- 178
- 315

- 85,501
- 44
- 121
- 160
-
2In addition to **bind(2)** to a single address, you can also bind to more addresses by using multiple `Connector` elements. https://access.redhat.com/solutions/873953 – Low power Apr 20 '19 at 06:39
-
I am getting same issue can you pl check my [question](https://stackoverflow.com/q/75752438/6854117)? – Moeez Mar 16 '23 at 05:31
it's well documented here:
https://cwiki.apache.org/confluence/display/TOMCAT/Connectors#Connectors-Q6
How do I bind to a specific ip address? - "Each Connector element allows an address property. See the HTTP Connector docs or the AJP Connector docs". And HTTP Connectors docs:
http://tomcat.apache.org/tomcat-7.0-doc/config/http.html
Standard Implementation -> address
"For servers with more than one IP address, this attribute specifies which address will be used for listening on the specified port. By default, this port will be used on all IP addresses associated with the server."
-
I am getting same issue can you pl check my [question](https://stackoverflow.com/q/75752438/6854117)? – Moeez Mar 16 '23 at 05:51
It may be worth mentioning that running tomcat as a non root user (which you should be doing) will prevent you from using a port below 1024 on *nix. If you want to use TC as a standalone server -- as its performance no longer requires it to be fronted by Apache or the like -- you'll want to bind to port 80 along with whatever IP address you're specifying.
You can do this by using IPTABLES to redirect port 80 to 8080.

- 639
- 1
- 6
- 16
-
2Your answer should be a comment. It does not provide a resolve for changing the `I.P.` Tomcat binds to. – Edward J Beckett Mar 31 '15 at 07:13
-
Anyone running TC on linux is going to run into the port issue above. – Hal50000 Mar 22 '16 at 02:55
-
I run tomcat on several distros... never witnessed your assertion... the accepted answer is correct. – Edward J Beckett Mar 22 '16 at 02:59
-
-
Then you run your TC with a port above 1024 -- not a real site. Enjoy your tin plated internet sheriffs badge – Hal50000 Mar 22 '16 at 03:06
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/107049/discussion-between-hal50000-and-eddie-b). – Hal50000 Mar 22 '16 at 15:38
-
I am getting same issue can you pl check my [question](https://stackoverflow.com/q/75752438/6854117)? – Moeez Mar 16 '23 at 05:51