Android DHCP Port Redirection


I am working on a MirrorLink implementation for the Google Pixel (Android 8.1.0). I must implement a DHCP server; however, Android applications cannot listen on reserved ports.

The Android application is listening for DHCP DISCOVERY broadcasts on UDP port 6700. My intent is to port forward the DHCP traffic to 6700 so my application can handle the DHCP request.

I cannot find a combination of iptables rules that result in DHCP traffic reaching my application. If I send a DHCP DISCOVERY directly to port 6700 I receive the traffic.

# iptables -S

-N bw_costly_rmnet_data0
-N bw_costly_shared
-N bw_costly_tun0
-N bw_data_saver
-N bw_happy_box
-N bw_penalty_box
-N fw_dozable
-N fw_powersave
-N fw_standby
-N natctrl_FORWARD
-N natctrl_tether_counters
-N nm_mdmprxy_doze_mode_skip
-N nm_mdmprxy_iface_pkt_fwder
-N oem_fwd
-N oem_out
-N st_clear_caught
-N st_clear_detect
-N st_penalty_log
-N st_penalty_reject

# iptables -t nat -S

-N natctrl_nat_POSTROUTING
-N oem_nat_pre

I have tried various combinations of the following rules:

iptables -A INPUT -i ncm0 -p udp --dport 67 -J REDIRECT --to-port 6700
iptables -A FORWARD -i ncm0 -p udp --dport 6700 -j ACCEPT
iptables -A INPUT -i ncm0 -p udp --dport 6700 -j ACCEPT
iptables -A PREROUTING -t nat -i ncm0 -p udp --dport 67 -j REDIRECT --to-port 6700

I suspect either a dire misunderstanding of iptables configuration (likely), special considerations for DHCP traffic, or Android/device specific conflicts.

I would appreciate any help getting this to work. It's the last barrier to achieving the MirrorLink implementation.

I have root access to the device if that wasn't clear already.

For absolute clarity - the MirrorLink device sends a DHCP DISCOVERY request (UDP port 67) to the Android device over a USB ethernet connection (CDC-NCM). The Google Pixel and probably most AOSP devices expose this interface as ncm0. Android applications can't listen on IANA well-known reserved ports, hence the need for internal port redirection to the 1024 - 49151 range. The Android device is reponsible for operating a DHCP server and returning a DHCP offer to the MirrorLink device.


I solved this problem using DNAT redirection instead of port redirection, due to some limitations of REDIRECT involving broadcast traffic.

iptables -I INPUT -p udp --dport 67 -j ACCEPT
iptables -I INPUT -p udp --dport 6700 -j ACCEPT
iptables -I PREROUTING -t nat -i ncm0 -p udp -src --dport 67 -j DNAT --to


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes