Changing Host IP Address in Flask (original) (raw)

Last Updated : 29 May, 2026

By default, a Flask application runs on 127.0.0.1:5000, which makes it accessible only on the same machine. To access the application from other devices on the same network, the host IP address can be changed.

Using host Parameter

host parameter in app.run() is used to specify the IP address on which the application should run. Setting the host to a local network IP allows other devices on the same network to access the application.

Python `

from flask import Flask app = Flask(name)

@app.route('/') def hello(): return 'Hello, World! this application runing on 192.168.0.105'

if name == 'main': app.run(host='192.168.0.105')

`

**Output

host-parameter

Snippet of terminal

development-server

Snippet of Development Server

Now, the app will be accessible from other devices on the same network using 192.168.0.105:5000.

Using Command Line

Instead of modifying the script, we can set the host and port directly when running the app from the terminal. Here are the steps:

1. Set the Flask app environment variable:

set FLASK_APP=app.py

2. Run the Flask app with a custom IP and port:

flask run --host=192.168.0.105 --port=5000

Python `

from flask import Flask app = Flask(name)

@app.route('/') def hello(): return 'Hello, World!'

if name == 'main': app.run()

`

**Output

development-server

Snippet of terminal

Changing Host IP Address in Flask

Snippet of Development Server

We can make it accessible on a different IP by using the command "flask run --host=192.168.0.105 --port=5000".