How to Use ChatGPT Even When Behind a VPN

3 min

language: ja bn en es hi pt ru zh-cn zh-tw

Hello everyone.
When using a VPN, ChatGPT often detects and blocks access, so this method is effective when you want to bypass it for specific services.

Check the IP Address Pointed to by the Domain

Use dig to query DNS and check the returned IP address.

# dig +short chat.openai.com
chat.openai.com.cdn.cloudflare.net.
104.18.37.228
172.64.150.28

I see.

Route Through the Default Gateway on the VPN Server Side

On the VPN server side, use route add to route through the default network, preventing VPN communication for specific services.
On a VPS, it's often changed from 192.168.1.1, so confirm it as follows.

netstat -nr | grep default

Then, change the routing as follows.

route add <IP_ADDRESS_RETURNED_BY_DIG_COMMAND> <DEFAULT_GATEWAY>

With this, you should be able to open ChatGPT.

Script for Automatic Routing Configuration

Since the IP address of chat.openai.com changes periodically, this needs to be executed regularly.
Therefore, you can simply dig and route add within a script as a cron job.

#!/bin/bash

# Define the list of domains
DOMAINS=("chat.openai.com" "example.com" "google.com")

# Default gateway
GATEWAY="192.168.1.1"

# Get IP addresses for each domain and add routing
for DOMAIN in "${DOMAINS[@]}"; do
  # Get the IP address of the domain
  IP_ADDRESSES=$(dig +short $DOMAIN | grep [0-9])

  # Add routing for each IP
  for IP in $IP_ADDRESSES; do
    route add $IP $GATEWAY
  done
done

With this, you can easily add domains and configure routing for services other than ChatGPT that might be blocked. ※The above assumes execution with root privileges.


That's all for now. Thank you.

Related Posts