@@ -167,8 +167,74 @@ def __run_config_server(self) -> None:
167167
168168 self .run_service ([command , command ], "flask_config_server" , separate_process = True )
169169
170+ def __fix_network_interface_in_sockd_conf (self ) -> None :
171+ """
172+ Auto-detects the primary network interface and updates /etc/sockd.conf.
173+ This fixes compatibility with R7i instances which use 'enp39s0' instead of 'ens5'.
174+ """
175+ logging .info ("Auto-detecting network interface for SOCKS proxy configuration" )
176+
177+ try :
178+ # Get the primary network interface (exclude loopback)
179+ result = subprocess .run (
180+ ["ip" , "-o" , "link" , "show" ],
181+ capture_output = True ,
182+ text = True ,
183+ check = True
184+ )
185+
186+ primary_interface = None
187+ # Try to find an interface in UP state first
188+ for line in result .stdout .split ('\n ' ):
189+ if line .strip () and 'lo:' not in line and 'state UP' in line :
190+ # Extract interface name (format: "2: ens5: <BROADCAST...")
191+ parts = line .split (':' )
192+ if len (parts ) >= 2 :
193+ primary_interface = parts [1 ].strip ()
194+ break
195+
196+ if not primary_interface :
197+ # Fallback: just get the first non-loopback interface
198+ for line in result .stdout .split ('\n ' ):
199+ if line .strip () and 'lo:' not in line :
200+ parts = line .split (':' )
201+ if len (parts ) >= 2 :
202+ primary_interface = parts [1 ].strip ()
203+ break
204+
205+ if not primary_interface :
206+ logging .warning ("Could not detect primary network interface, using default 'ens5'" )
207+ primary_interface = "ens5"
208+
209+ logging .info (f"Detected primary network interface: { primary_interface } " )
210+
211+ # Read the current sockd.conf
212+ with open ('/etc/sockd.conf' , 'r' ) as f :
213+ config = f .read ()
214+
215+ # Replace any external interface declaration
216+ new_config = re .sub (
217+ r'external:\s+\w+' ,
218+ f'external: { primary_interface } ' ,
219+ config
220+ )
221+
222+ # Write back the updated config
223+ with open ('/etc/sockd.conf' , 'w' ) as f :
224+ f .write (new_config )
225+
226+ logging .info (f"Updated /etc/sockd.conf with interface: { primary_interface } " )
227+
228+ except Exception as e :
229+ logging .error (f"Failed to auto-detect network interface: { e } " )
230+ logging .info ("Continuing with existing /etc/sockd.conf configuration" )
231+
170232 def __run_socks_proxy (self ) -> None :
171233 logging .info ("Starts the SOCKS proxy service" )
234+
235+ # Fix network interface for R7i compatibility
236+ self .__fix_network_interface_in_sockd_conf ()
237+
172238 command = ["sockd" , "-D" ]
173239
174240 # -d specifies debug level
0 commit comments